SQL Data Types (Numeric - Exact)
Type |
Minimum |
Maximum |
Storage |
bigint |
-9,223,372,036,854,775,808 |
9,223,372,036,854,775,807 |
8 Bytes |
int |
-2,147,483,648 |
2,147,483,647 |
4 Bytes |
smallint |
-32,768 |
32,767 |
2 Bytes |
tinyint |
0 |
255 |
1 Byte |
bit |
true (1) |
false (0) |
1 Byte for every 8 bits |
decimal(p,s) |
-10^38 + 1 |
10^38 - 1 |
Up to 17 Bytes |
numeric |
-10^38 + 1 |
10^38 - 1 |
Up to 17 Bytes |
money |
-922,337,203,685,477.5808 |
922,337,203,685,477.5807 |
8 Bytes |
smallmoney |
-214,748.3648 |
214,748.3647 |
4 Bytes |
SQL Data Types (Character Strings)
Type |
Range/Category |
Storage |
char(n) |
Non-Unicode Characters |
n Bytes |
varchar(n) |
Non-Unicode Characters |
n Bytes |
varchar(max) |
Non-Unicode Characters |
2^31-1 Bytes |
text |
Non-Unicode Characters |
2^31-1 Bytes |
nchar(n) |
Unicode Characters |
n Bytes |
nvarchar(n) |
Unicode Characters |
n Bytes |
nvarchar(max) |
Unicode Characters |
2^31-1 Bytes |
ntext |
Unicode Characters |
2^30-1 Bytes |
binary(n) |
Binary Data |
n Bytes |
varbinary(n) |
Binary Data |
n Bytes |
varbinary(max) |
Binary Data |
Actual length of the data + 2 Bytes |
image |
Binary Data |
2^31-1 Bytes |
SQL Data Types (Numeric - Approximate)
Type |
Range |
Storage |
float(n) |
-1.79E+308 to -2.23E-308, 0, 2.23E-308 to 1.79E+308 |
4 or 8 Bytes* |
real |
-3.40E+38 to -1.18E-38, 0, and 1.18E-38 to 3.40E+38 |
4 Bytes |
* Depends on the value of "n".
SQL Data Types (Spatial)
Type |
Range |
geography |
Latitude & Longitude values |
geometry |
Euclidean (flat) coordinate system (x/y values) |
SQL Data Types (Other)
Type |
Range |
Storage |
uniqueidentifier |
Fixed-length 32-character Hexidecimal |
16 Bytes |
xml |
Well-formed XML Data |
2 Gigabytes |
|
|
C# Data Types (Numeric)
Type |
Minimum |
Maximum |
.NET Class |
byte |
0 |
255 |
System.Byte |
sbyte |
-128 |
127 |
System.SByte |
short |
-32,768 |
32,767 |
System.Int16 |
ushort |
0 |
65,535 |
System.UInt16 |
int |
-2,147,483,648 |
2,147,483,647 |
System.Int32 |
uint |
0 |
4,294,967,295 |
System.UInt32 |
long |
-9,223,372,036,854,775,808 |
9,223,372,036,854,775,807 |
System.Int64 |
ulong |
0 |
18,446,744,073,709,551,615 |
System.UInt64 |
float |
-3.402823e38 |
3.402823e38 |
System.Single |
double |
-1.79769313486232e308 |
1.79769313486232e308 |
System.Double |
decimal |
-79,228,168,514,264,337,593,543,950,335 |
79,228,162,514,264,337,593,543,950,335 |
System.Decimal |
C# Data Types (Character Strings)
Type |
Range |
.NET Class |
char |
A single Unicode character |
System.Char |
string |
A string of Unicode characters |
System.String |
C# Data Types (Date & Time)
Type |
Minimum |
Maximum |
.NET Class |
DateTime |
01/01/0001 00:00:00.0000000 |
12/31/9999 23:59:59.9999999 |
System.DateTime |
TimeSpan |
-10,675,199 days* |
10,675,199 days* |
System.TimeSpan |
* Values are approximate, based on long.MinValue and long.MaxValue for total number of ticks.
C# Data Types (Other)
Type |
Range |
.NET Class |
bool |
True or False |
System.Boolean |
object |
An object. |
System.Object |
Guid |
A 32-character Hexidecimal value |
System.Guid |
SQL to C# Conversion
SQL Data Type |
C# Type |
tinyint |
byte |
smallint |
short |
int |
int |
bigint |
long |
float |
float |
decimal |
decimal |
nvarchar |
string |
varchar |
string |
char |
string |
bit |
bool |
datetime2 |
DateTime |
geography |
DbGeography |
uniqueidentifier |
Guid |
time* |
DateTime/TimeSpan* |
* Time is stored as a DateTime on the data object, however, there are times when it is converted into a TimeSpan in order to perform certain operations.
|