C#
SQL Server
DataTypes
Programming
Database

C# equivalents of SQL Server data types

Codemia Knowledge Hub ·

Most SQL Server types map directly to a C# type: bit to bool, tinyint to byte, smallint to short, int to int, bigint to long, decimal/numeric/money to decimal, float to double, real to float, string types to string, most date types to DateTime (datetimeoffset to DateTimeOffset, time to TimeSpan), and uniqueidentifier to Guid. The tables below give the full mapping.

Numeric types

Sizes and precision differ between types, so pick the C# type that matches the column's range:

SQL Server Data TypeC# Equivalent Data TypeDescription
bitboolBoolean value, 0 or 1
tinyintbyteUnsigned 8-bit integer, range from 0 to 255
smallintshortSigned 16-bit integer, range from -32,768 to 32,767
intintSigned 32-bit integer, range from -2,147,483,648 to 2,147,483,647
bigintlongSigned 64-bit integer
decimal (p,s)decimal, System.DecimalExact fixed-point numeric value, specified precision (p) and scale (s)
numeric (p,s)decimal, System.DecimalEquivalent to decimal with specified precision and scale
smallmoneydecimalCurrency values, with a fixed precision
moneydecimalLarge range currency values
floatdoubleFloating point numeric data, 64-bit
realfloatSingle-precision floating-point, 32-bit

Character and string types

SQL Server Data TypeC# Equivalent Data TypeDescription
char(n)string, char[]Fixed length non-Unicode character data of length n
varchar(n)stringVariable length non-Unicode character data with a max length of n
textstringVariable length non-Unicode data with max storage of 2^31-1 bytes
nchar(n)string, char[]Fixed-length Unicode character data
nvarchar(n)stringVariable-length Unicode character data storage
ntextstringLarge Unicode text data

Date and time types

SQL Server Data TypeC# Equivalent Data TypeDescription
dateDateTimeDate data without the time component
datetimeDateTimeCombination of date and time components
datetime2DateTimeExtended precision datetime data type
datetimeoffsetDateTimeOffsetIncludes timezone offset information
smalldatetimeDateTimeDate and time data from 1900-01-01 through 2079-06-06
timeTimeSpanRepresents time of day

Binary types

Binary types store data such as images or files:

SQL Server Data TypeC# Equivalent Data TypeDescription
binary(n)byte[]Fixed-length binary data
varbinary(n)byte[]Variable-length binary data
imagebyte[]Variable-length binary data for large amounts

uniqueidentifier

SQL Server's uniqueidentifier holds GUIDs and maps to Guid in C#.

Avoiding mapping mistakes

Mismatched types can cause exceptions or truncation, which leads to data loss or corruption during retrieval, updates and migrations. Check the precision and range on both sides and test thoroughly. ORM frameworks such as Entity Framework or Dapper help manage these mappings.

  1. Validation: Apply validation and constraints in both the database and the application layer.
  2. Precision and scale: For decimal types, account for precision and scale to prevent overflow errors.
  3. Date and time: Handle DateTime and DateTimeOffset carefully because of time zones.

Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design