HOWTO · Csharp
C# Equivalent of SQL Server Data Types
In this article, you will understand the C# programming language's data types comparable to those found in SQL server data types.
In this article, you will understand C# programming language’s data types comparable to those in SQL server data types. Let’s look at the following data types supported by the SQL server and discuss the equivalent data types in C#.
C# Equivalent of SQL Server Data Types
Exact Numerics
Integer types are those that can store int values. The following is a distribution of bytes for int types:
| Data Type |
Description |
bigint |
It can hold up to 8 bytes and should be used when the integer data type cannot adequately contain the data. bigint is equal to the data types Int64 and NullableInt64> in C#. |
smallint |
It can hold up to 2 bytes and store whole numbers between a specified minimum and maximum. The data type smallint is identical to the Int16 type used in C#. |
int |
It can hold up to 4 bytes and is similar to a smallint in that it holds the full integer, but its range’s lower and upper boundaries vary depending on what is declared. The data type int is equal to Int32 in C#. |
smallmoney |
It can hold up to 4 bytes and be used for monetary or currency values. |
tinyint |
It can hold up to 1 byte and store whole numbers up to 255. |
bit |
It can hold up to 1 byte and store Null values. |
Approximate Numerics
| Data Type |
Description |
float |
It is a form of data representing approximate numbers. Its storage relies upon value. |
real |
It can hold up to 4 bytes. |
Date and Time
| Data Type |
Description |
date |
It can hold up to 3 bytes. As the name describes, it stores dates, and its default format is YYYY-MM-DD. |
smalldatetime |
It can hold up to 4 bytes. It is accurate to the minute and can specify a date together with the current time of day. |
time |
It can hold up to 5 bytes. An accuracy of 100 nanoseconds is provided by time. |
datetime2 |
It can hold up to 8 bytes. Its default format is YYYY-MM-DD. |
Datetimeoffset |
It can hold up to 10 bytes. It is comparable to a datetime2 data type but contains a time zone offset value. |
datetime |
It can hold up to 8 bytes. By using datetime, we can declare not just a date but also an exact time, including fractional seconds. |
Character Strings
| Data Type |
Description |
nvarchar |
It can store up to n bytes. n is the string size. |
nchar |
It can hold up to n bytes. nchar offers a character data type with a predetermined width. |
text |
It can hold up to n and 4 bytes. It is known as a character data type with changeable length. |
Unicode Character Strings
| Data Type |
Description |
nvarchar |
It can store up to 2*n. nvarchar is a variable-width Unicode string. |
ntext |
It can hold up to 2*string-length bytes. |
nchar |
It can hold up to 2*n. nchar is a fixed-width Unicode string. |
Binary Strings
| Data Type |
Description |
varbinary |
It can hold string actual-length + 2 bytes. |
binary |
It can hold up to n bytes. binary is a fixed-width string. |
Other Data Types
| Data Type |
Description |
xml |
It is a unique data type that can store XML information in tables inside an SQL server. |
table |
It is a specialized data type used in table-valued functions to store a result set temporarily. The data that we get from this may be processed at a later time. |
hierarchyid |
The length of the hierarchyid system data type is variable. This symbol may represent the position in a hierarchy. |
About the author
I have been working as a Flutter app developer for a year now. Firebase and SQLite have been crucial in the development of my android apps. I have experience with C#, Windows Form Based C#, C, Java, PHP on WampServer, and HTML/CSS on MYSQL, and I have authored articles on their theory and issue solving. I'm a senior in an undergraduate program for a bachelor's degree in Information Technology.
View author profile →