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 Type | C# Equivalent Data Type | Description |
bit | bool | Boolean value, 0 or 1 |
tinyint | byte | Unsigned 8-bit integer, range from 0 to 255 |
smallint | short | Signed 16-bit integer, range from -32,768 to 32,767 |
int | int | Signed 32-bit integer, range from -2,147,483,648 to 2,147,483,647 |
bigint | long | Signed 64-bit integer |
decimal (p,s) | decimal, System.Decimal | Exact fixed-point numeric value, specified precision (p) and scale (s) |
numeric (p,s) | decimal, System.Decimal | Equivalent to decimal with specified precision and scale |
smallmoney | decimal | Currency values, with a fixed precision |
money | decimal | Large range currency values |
float | double | Floating point numeric data, 64-bit |
real | float | Single-precision floating-point, 32-bit |
Character and string types
| SQL Server Data Type | C# Equivalent Data Type | Description |
char(n) | string, char[] | Fixed length non-Unicode character data of length n |
varchar(n) | string | Variable length non-Unicode character data with a max length of n |
text | string | Variable length non-Unicode data with max storage of 2^31-1 bytes |
nchar(n) | string, char[] | Fixed-length Unicode character data |
nvarchar(n) | string | Variable-length Unicode character data storage |
ntext | string | Large Unicode text data |
Date and time types
| SQL Server Data Type | C# Equivalent Data Type | Description |
date | DateTime | Date data without the time component |
datetime | DateTime | Combination of date and time components |
datetime2 | DateTime | Extended precision datetime data type |
datetimeoffset | DateTimeOffset | Includes timezone offset information |
smalldatetime | DateTime | Date and time data from 1900-01-01 through 2079-06-06 |
time | TimeSpan | Represents time of day |
Binary types
Binary types store data such as images or files:
| SQL Server Data Type | C# Equivalent Data Type | Description |
binary(n) | byte[] | Fixed-length binary data |
varbinary(n) | byte[] | Variable-length binary data |
image | byte[] | 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.
- Validation: Apply validation and constraints in both the database and the application layer.
- Precision and scale: For decimal types, account for precision and scale to prevent overflow errors.
- Date and time: Handle
DateTimeandDateTimeOffsetcarefully because of time zones.
Related reading
- C equivalent of the IsNull function in SQL Server
- c working with Entity Framework in a multi threaded server
- Calculate difference between two datetimes in MySQL
- Calculate size of items in my Amazon DynamoDB table
- C equivalent to Java's Exception.printStackTrace?
- C Events and Thread Safety
- Calculating the size of a table in Cassandra
- Calling external services (Rest api)/database CRUD operations within Orleans Grain
System design interview problems on this topic
- Design a Distributed OLTP Database: solution and walkthrough
- Design a Wide Column Database: solution and walkthrough
- Design a Key Value Store: solution and walkthrough
- Design a Web Cache: solution and walkthrough

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseSystem Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.