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
Integer types are those that can store int values. The following is a distribution of bytes for int types:
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#.
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#.
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#.
It can hold up to 4 bytes and be used for monetary or currency values.
It can hold up to 1 byte and store whole numbers up to 255.
It can hold up to 1 byte and store Null values.
It is a form of data representing approximate numbers. Its storage relies upon value.
It can hold up to 4 bytes.
Date and Time
It can hold up to 3 bytes. As the name describes, it stores dates, and its default format is YYYY-MM-DD.
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.
It can hold up to 5 bytes. An accuracy of 100 nanoseconds is provided by time.
It can hold up to 8 bytes. Its default format is YYYY-MM-DD.
It can hold up to 10 bytes. It is comparable to a datetime2 data type but contains a time zone offset value.
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.
It can store up to n bytes. n is the string size.
It can hold up to n bytes. nchar offers a character data type with a predetermined width.
It can hold up to n and 4 bytes. It is known as a character data type with changeable length.
Unicode Character Strings
It can store up to 2*n. nvarchar is a variable-width Unicode string.
It can hold up to 2*string-length bytes.
It can hold up to 2*n. nchar is a fixed-width Unicode string.
It can hold string actual-length + 2 bytes.
It can hold up to n bytes. binary is a fixed-width string.
Other Data Types
It is a unique data type that can store XML information in tables inside an SQL server.
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.
The length of the hierarchyid system data type is variable. This symbol may represent the position in a hierarchy.
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.