In our daily development process, when designing a database, we often encounter problems with selecting data types, choosing what type of data is most appropriate, and then choosing the corresponding CLR type when we create the corresponding entity in the project. In response to these questions, this article was born.
SQL Server data types |
Number of bytes occupied |
Representation Range |
The corresponding CLR type |
Applicable scenarios |
Char |
CHAR (n) |
|
System.String |
Use char (2) to represent a type or state (tinyint is recommended instead) |
varchar |
VARCHAR (n) |
1~8000 |
System.String |
A string containing only English characters |
nvarchar |
nvarchar (n) |
1~4000 |
System.String |
A string containing Chinese characters |
Int |
4 bytes |
2,147,483,648 to 2,147,483,647 |
System.Int32 |
Represents an integer, such as a self-increment ID |
bigint |
8 bytes |
9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 |
System.Int64 (Long) |
Represents a long integer, such as a self-increment ID (with a large number of cases) |
Decimal |
5~17 bytes |
|
System.Decimal |
Amount |
tinyint |
1 bytes |
0~255 |
System.Byte |
Type and state, better than char (2) extensibility |
Bit |
|
0,1 or null |
System.Boolean |
Generally used to indicate yes and no two situations |
Datetime |
8 bytes |
January 1, 1753 to December 31, 9999 |
System.DateTime |
Represents a date and time |
Time |
|
|
System.TimeSpan |
Represents a time interval, such as timing |
varbinary |
  |
system.byte |
|