#What are the common data types in databases?
1. Integer data type: The integer data type is one of the most commonly used data types.
1. INT (INTEGER)
INT (or INTEGER) data type stores values from -2 to the 31st power (-2, 147, 483, 648) to all positive and negative integers between 2 to the 31st power -1 (2, 147, 483, 647). Each INT type data is stored in 4 bytes, of which 1 bit represents the sign of the integer value, and the other 31 bits represent the length and size of the integer value.
2, SMALLINT
SMALLINT data type stores from -2 to the 15th power (-32, 768) to 2 to the 15th power -1 (32, 767 ) between all positive and negative integers. Each SMALLINT type data occupies 2 bytes of storage space, of which 1 bit represents the sign of the integer value, and the other 15 bits represent the length and size of the integer value.
2. Floating point data type: Floating point data type is used to store decimal decimals. Floating-point numerical data is stored in SQL Server using round up (or called rounding only) method.
1. REAL data type
REAL data type can be accurate to the 7th decimal place, and its range is from -3.40E -38 to 3.40E 38 . Each REAL type data occupies 4 bytes of storage space.
2. FLOAT
The FLOAT data type can be accurate to the 15th decimal place, and its range is from -1.79E -308 to 1.79E 308. Each FLOAT type data occupies 8 bytes of storage space. The FLOAT data type can be written in the form of FLOAT[n]. n specifies the precision of FLOAT data. n is an integer value between 1 and 15.
When n ranges from 1 to 7, a REAL type data is actually defined, and the system uses 4 bytes to store it; when n ranges from 8 to 15, the system considers it to be a FLOAT type, and uses 8 bytes to store it.
3. Binary data type
1. BINARY
BINARY data type is used to store binary data. Its definition form is BINARY (n), n represents the length of the data, and its value ranges from 1 to 8000. The size of BINARY type data must be specified when using it, which should be at least 1 byte. BINARY type data occupies n 4 bytes of storage space.
When entering data, the character "0X" must be added in front of the data as a binary identifier. For example, if you want to enter "abc", you should enter "0xabc". If the input data is too long, the excess part will be truncated. If the input data has an odd number of digits, a 0 will be added after the starting symbol "0X". For example, the above "0xabc" will be automatically changed to "0x0abc" by the system.
2. VARBINARY
The definition form of VARBINARY data type is VARBINARY(n). It is similar to the BINARY type. The value of n is also from 1 to 8000. If the input data is too long, the excess part will be truncated.
The difference is that the VARBINARY data type has the characteristic of variable length, because the storage length of the VARBINARY data type is the actual value length of 4 bytes. When the BINARY data type allows NULL values, it will be treated as a VARBINARY data type.
4. Logical data type
1. BIT: The BIT data type occupies 1 byte of storage space, and its value is 0 or 1 . If you enter a value other than 0 or 1, it will be treated as 1. The BIT type cannot be defined as a NULL value (the so-called NULL value refers to a null value or a meaningless value).
5. Character data type: Character data type is the most commonly used data type. It can be used to store various letters, numeric symbols, and special symbols. Under normal circumstances, when using character type data, single quotes ' or double quotes must be added before and after it.
1, CHAR
CHAR data type The definition form is CHAR[(n)]. Each character and symbol stored in the CHAR type occupies one byte of storage space. n represents the storage space occupied by all characters, and the value of n is 1 to 8000, that is Holds 8000 ANSI characters.
If n value is not specified, the system default value is 1. If the number of characters of the input data is less than n, the system will automatically add spaces after it to fill the set space .If the input data is too long, the excess part will be cut off.
Extended information:
SQL includes all operations on the database, mainly composed of 4 It consists of three parts:
1. Data definition: This part is also called "SQL DDL", which defines the logical structure of the database, including defining the database, basic tables, views and indexes.
2. Data manipulation: This part is also called "SQL DML", which includes two major types of operations: data query and data update. Data update includes three operations: insertion, deletion and update.
3. Data Control: Control of user access to data includes authorization of basic tables and views, description of integrity rules, transaction control statements, etc.
4. Regulations on the use of embedded SQL language: stipulates that SQL statements must be used in the host language Rules used in the program.
Recommended tutorial: "sql video tutorial"
The above is the detailed content of What are the common data types in databases?. For more information, please follow other related articles on the PHP Chinese website!