Integer type
|
|
Bigint |
The range is-263 (-9223372036854775808) ~263-1 (9223372036854775807), with a precision of 19, a scale of 0, and a length of 8 bytes. |
Int |
The range is-231 (-2,147,483,648) ~231-1 (2,147,483,647), with a precision of 10, a scale of 0, and a length of 4 bytes. |
smallint |
The range is-215 (-32768) ~215-1 (32767), with a precision of 5, a scale of 0, and a length of 2 bytes. |
tinyint |
The range is 0~255, with a length of 1 bytes, a precision of 3, a scale of 0, and a length of 1 bytes. |
Exact integer type
integers + decimals, all numbers are valid bits, including decimal and numeric, the only difference is that decimal cannot be used for columns with the IDENTITY keyword. The format for declaring exact integer data is Numeric|decimal (P[,s]), where p is precision, S is the number of decimal digits, and S has a default value of 0.
Decimal and numeric store digital data of fixed precision and decimal digits from -1038+1 to 1038–1, whose storage length varies with precision, with a minimum of 5 bytes and a maximum of 17 bytes.
When the accuracy is 1~9, the storage byte length is 5;
When the accuracy is 10~19, the storage byte length is 9;
When the accuracy is 20~28, the storage byte length is 13;
When the accuracy is 29~38, the storage byte length is 17.
Approximate numerical type
Real: Using 4 bytes of data, the number of tables ranges from -3.40E+38 to 3.40E+38, and the data precision is 7 digits valid.
float: The n range of values in the definition is 1~53, which indicates its precision and storage size.
When n is between 1~24, a real data is actually defined, with a storage length of 4 bytes and a precision of 7 digits, and when n is between 25~53, the storage length is 8 bytes and the precision is 15 digits valid.
When the default n, represents n between 25~53. The number of float data ranges from -1.79E+308 to 1.79E+308.
Currency type
Money: The number of data ranges from 263 (-922337203685477.5808) ~263-1 (922337203685477.5807), with a precision of 19, a scale of 4, and a length of 8 bytes. The range of money is the same as the bigint, except that the money type has 4 decimal places, in fact, money is calculated by integer, but the decimal point is fixed to the last 4 bits.
SmallMoney: The number range is –231 ( -2,147,48.3648) ~231-1 (2,147,48.3647), with a precision of 10, a scale of 4, and a length of 4 bytes. It can be seen that the relationship between smallmoney and int is like the relationship between money and bigint.
When you insert a value of type money or smallmoney into a table, you must precede the data with a currency representation symbol ($), and the data cannot have a comma (,) in the middle, or a minus sign (-) after the symbol $ if the currency value is negative. For example: $15000.32,$680,$-20000.9088 are the correct representation of the currency data.
-bit type
Bit-type data in SQL Server is equivalent to logical data in other languages, it stores only 0 and 1, and is one byte in length. Note, however, that SQL Server optimizes storage for bit type columns in a table: if there are no more than 8 bit columns in a table, these columns will be stored as a byte, and if there are 9 to 16 bit columns in the table, the columns will be stored as two bytes, and so are the more columns.
When 0 o'clock is assigned to the bit type data, its value is 0, and the value is 1 if it is not 0 (for example, 100).
If a column in a table is a bit type of data, it is not allowed to be null (described in this section for null values) and is not allowed to be indexed.
Character type
char[(N)]
Fixed-length character data type, where n defines the length of the character data, n is between 1 and 8000 and defaults to 1. When a column in a table is defined as a char (n) type, if the actual string length to be stored is less than n, a space is added at the end of the string to reach the length n, so the length of char (n) is n. For example, if a column has a data type of char (20) and the string entered is "ahjm1922", the character ahjm1922 and 12 spaces are stored. If the number of characters entered exceeds N, the part that is exceeded is truncated.
varchar[(N)]
Variable-length character data type where n is exactly the same as N in a fixed-length character char, but here n represents the maximum length a string can reach. The length of varchar (n) is the actual number of characters of the input string, not necessarily n. For example, the data type of a column in a table is varchar (100) and the string entered is "ahjm1922", then the character ahjm1922 is stored, and its length is 8 bytes.
Unicode character type
Unicode is a "Unified character encoding standard" that supports the storage and processing of character data in non-English languages internationally.
NCHAR is a data type for fixed-length Unicode data
Nvarchar are data types for variable-length Unicode data, both using the UNICODEUCS-2 character set.
lnchar[(n)]:nchar[(n)] is a fixed-length Unicode character data that contains n characters, the value of n is between 1 and 4,000, and the default is 1. Length is 2n bytes. If you enter a string that is less than n long, it will be filled with white space characters.
lnvarchar[(n)]:nvarchar[(n)] is a variable-length Unicode character data with a maximum of n characters, the value of n is between 1 and 4,000, and the default is 1. The length is twice times the number of characters entered.
In fact, the use of nchar, nvarchar and char, varchar is very similar, except that the character set is different (the former uses the Unicode character set, which uses the ASCII character set).
Text type
When you need to store large amounts of character data, you can use text-based data at this time.
Text types include text and ntext, which correspond to ASCII characters and Unicode characters, respectively. The text type can represent a maximum length of 231-1 (2,147,483,647) characters, and the storage length of the data is the actual number of characters in bytes. ntext can represent a maximum length of 230-1 (1,073,741,823) Unicode characters, whose data is stored in twice times the length of the actual number of characters (in bytes). Binary type
A binary data type represents a bit data stream,
binary[(n)]: fixed-length n byte binary data. The n values range from 1 to 8,000, and the default is 1. Binary (n) data has a storage length of n+4 bytes. If the input data length is less than n, then the insufficient portion is filled with 0, and if the input data length is greater than n, the excess portion is truncated.
When entering a binary value, add 0x to the front of the data, and you can use a number symbol of 0-9, a-f (the letter case can be). Therefore, binary data is sometimes referred to as hexadecimal data. For example, 0xFF, 0x12a0 represent values FF and 12a0 respectively. Since the maximum number of bytes per byte is FF, the data in "0x" format takes up 1 bytes per two bits.
varbinary[(n)]:n byte variable-length binary data. The n values range from 1 to 8,000, and the default is 1. The storage length of the varbinary (n) data is the actual input data length + 4 bytes.
Date Time Type
Date-time type data is used to store date and time information, including both DateTime and smalldatetime classes.
The Datetime:datetime type can represent date and time data from January 1, 1753 to December 31, 9999 in a date range, The accuracy is 3% seconds (3.33 milliseconds or 0.00333 seconds), for example, a value of 1 to 3 milliseconds is represented as 0 milliseconds, and a value of 4 to 6 milliseconds is expressed as 4 milliseconds.
The datetime type data length is 8 bytes, and the date and time are stored using 4 bytes, respectively. The first 4 bytes are used to store the number of days from January 1, 1900 in the DateTime type data, and the positive numbers indicate that the date is after January 1, 1900 and the negative is the date before January 1, 1900. The latter 4 bytes are used to store the number of milliseconds in the datetime type data from 12:00 (24-hour).
The user enters the datetime type data as a string, the system also outputs the DateTime type data as a string, and the string form of the DateTime type data entered by the user into the system and the system output is called the "external form" of the datetime type data. Whereas datetime is stored in the system as an "internal form", SQL Server is responsible for the conversion between the two representations of datetime type data, including the legality check.
When the user gives the datetime type data value, the date part and the time part are given separately.
SQL Server primary data type data range