A data table is made up of multiple columns, and you must specify the data type of each column when you create the table. The following is a list of usage rules for common SQL Server data types .
Integer type |
Int |
The storage range is an integer between 2,147,483,648 and 2,147,483,647, and this type is often set by the primary key column. (4 bytes per value) |
smallint |
The storage range is an integer between 32,768 and 32,767 that stores data that is scoped to a specific numeric range. (2 bytes per value) |
tinyint |
The storage range is an integer between 0 and 255 to store a limited number of values. (1 bytes per value) |
bigint |
Storage range is an integer between 9,223,372,036,854,775,808 and 9,223,372,036,854,775,807 (8 bytes per value) |
Bit |
The value can only be 0 or 1, and when you enter a value other than 0, the system treats them as 1. Commonly used to indicate true and false, male and female two value choice. |
.
Numeric type |
Decimal (P,s) |
P is a precision (significant bit), which indicates the maximum number of digits that can be stored, the left and right sides of the decimal point are included, the default maximum bit is 38 bits, and S is the number of decimal places, which identifies the maximum number of digits that can be stored after the decimal, and the default minimum bit is 0 bits. For example: 123.45, then p=5,s=2 (memory size depends on accuracy p) |
Numeric (P,s) |
Numeric and decimal are functionally identical and are used to hold floating-point data with variable precision. |
Float |
Floating-point type, which is an approximate numeric type, and float (n) can store 1-53 of variable precision floating point values. (memory size depends on Precision N) |
Money |
Currency type, which can store data from 922 billion to 922 billion, accurate to four digits after the decimal point. (8 bytes per value) |
.
datetime type, binary type
TD colspan= "2" valign= "Top" width= "111" >
datetime |
Storage valid date range is 1753/1/1~9999/12/31 and can be accurate to 3.33 milliseconds. (8 bytes per value) |
smalldatetime |
Storage valid date range is 1900/1/1~2079/6/6, accurate to minutes. (4 bytes per value) |
image |
Although the type name is image, and does not mean that only picture binary data can be saved, It can actually hold any binary data 。 |
.
String type |
CHAR (M) |
A fixed-length string with a length of M. |
NCHAR (m) |
Internationalized fixed-length string with a length of M. |
varchar (m) |
A variable-length string that has a maximum length of m and must be a numeric value between 1 and 8,000. |
nvarchar (m) |
Internationalized variable-length string with a maximum length of m and must be a numeric value between 1 and 4,000. |
Text |
A variable-length string with a maximum length of 231-1 bytes. |
ntext |
Internationalized variable-length string with a maximum length of 230-1 characters. |
What is internationalization, is universal and standard. char, varchar, and text stored characters are based on the Asii encoding format, which can cause storage problems for characters in other encoded formats. The Unicode character set (universal code) is created to address the incompatibility of the character set, and all of its characters are represented in two bytes, meaning that the English character is also represented in two bytes. nchar, nvarchar, and ntext are stored in Unicode encoded characters. So in general, if it contains Chinese characters, use nchar, nvarchar, ntext, if only English characters, with char, varchar, text. |
Introduction to common SQL Server data types