Data types are columns, stored procedure parameters, and local variable data characteristics that determine the storage format of the data and represent different types of information.
Data types can be divided into system data types (the following table) and user-defined data types:
1. Binary type
Binary data types represent binary numbers with a maximum length of 255 bytes, and binary numbers can be composed of 0~9 and a~f or a~f characters, and binary numbers begin with a 0x identity, each of which is a group of two characters, constituting a byte, such as 0xf5.
Classification:
Fixed-length binary data type (with binary[(n)] declaration);
Variable-length binary data type (with varbinary[(n)] declaration).
Cases:
Delare @varl Binary (10)
Select @varl ' 0x10 ff AA '
Declare @var2 varbinary (64)
Note: When a data type defines a statement or a variable declaration, if you do not specify an n value, its length is 1, whereas in the Convert conversion function The default length is 30 if you do not specify an n value.
The difference between fixed length and variable length: For a fixed-length data type, it points to n bytes regardless of the actual length of the input value. If the assigned data degree exceeds n, the excess portion is truncated. The length of the variable length binary column is variable, it is the actual length of the string, but the maximum must not exceed the value specified by N. When the input data is longer than N, the remainder is truncated.
2. Character Type
You should enclose the data in single quotes when you enter character data. The character type also has a fixed length (char[(n))) and a variable length (varchar[(n))) of two species.
3. Date Time Type
Category: DateTime and smalldatetime
The datetime type has a data length of 8 bytes and the smalldatetime type has a data length of 4 bytes.
4. Integer type
Category: int, smallint, tinyint. The int length is 4 bytes, the smallint length is 2 bytes, and the tinyint length is 1 bytes.
5. Exact numeric type
Category: Decimal[(P[,s])] and numeric[(p[,s))]{p refers to precision, s refers to decimal places}
6. Approximate numerical type
Category: Float[(n)], real. The float data type can store positive and negative floating-point numbers, and n determines the binary precision, which can be 1 to 15. When the precision is between 1 and 7, it is equivalent to the real data type.
7. Currency type
Category: Money (8 bytes), smallmoney (4 bytes)
8. Bit data type
The bit data type is declared with the bit keyword, and its data is evaluated in two ways: 0 and 1. The system treats them as 1 when you enter values other than 0.
9. Timestamp data type
Declare with timestamp
10. Text and Image Types
Literal (text) and image (image) types are two variable-length data types. When inserting data into a text column, enclose the data in single quotes. When inserting data into an image column, you should add a 0x boot character to the data.
Identifier:
The naming rules for identifiers are as follows:
(1) The identifier length is 1 to 30 characters.
(2) The first character of the identifier must be a letter or _, @, #符号. where the @ and # symbols have special meaning: When an identifier begins with an @, it is a local variable; the first character of the identifier is # when it is a temporary database object, which, for a table or stored procedure, is represented as a local temporary object with a # symbol at the beginning of the name, including two # #时表示为全局临时对象.
(3) The character following the first character in an identifier can be a letter, a number, or a #, $, _ symbol.
(4) By default, spaces are not allowed within identifiers, and keywords are not allowed as identifiers, but special identifiers can be defined using quotes.