-128 to 127
1. bit [M]
Bit field type, where m represents the number of bits for each value, ranging from 1 to 64. If m is omitted, it defaults to 1.
2. Tinyint [(m)] [unsigned] [zero fill] m defaults to 4.
Very small integer. The signed range is-128 to 127. The unsigned range is 0 to 255.
3. Boolean type
It is a synonym for TINYINT( 1). A value of zero is considered false. Non-zero values are considered true.
4. smallint [(m)] [unsigned] [zero fill] m defaults to 6.
Small integer. The signed range is -32768 to 32767. The unsigned range is 0 to 65535.
5. Mediumint [(m)] [unsigned] [zero fill] m defaults to 9.
An integer of medium size. The signed range is -8388608 to 8388607. The unsigned range is 0 to 167772 15.
6.int [(m)] [unsigned] [zerofill] m is 1 1 by default.
An integer of ordinary size. The signed range is -2 147483648 to 2 147483647. The unsigned range is 0 to 4294967295.
7. Bigint [(m)] [unsigned] [zero fill] m defaults to 20.
Big integer. The signature range is -9223372036854775808 to 922375475807. The unsigned range is 0 to1844674073709551615.
Note: The m here does not represent the specific length stored in the database. I used to think that int(3) can only store numbers of three lengths, and int( 1 1) will store numbers of1,which is a big mistake.
1 and 4 in tinyint( 1) and tinyint(4) do not indicate the storage length, and only fields with zero padding are useful.
For example, tinyint(4), if the actual value is 2, if zerofill is specified in the column, the query result is 0002, and the left side is filled with 0.
-
Char is a fixed length type, while varchar is a variable length type. Their differences are as follows:
In a data column of type char(M), each value occupies m bytes. If the length is less than m, MySQL will add a space character to its right.
(In the retrieval operation, those filled space characters will be deleted. )
In a data column of varchar(M) type, each value only takes up just enough bytes to record its length plus one byte (that is, the total length is L+ 1 byte).
Rules used in MySQL to determine whether it is necessary to convert the listed types.
1. In the data table, if the length of each data column is fixed, the length of each data row will also be fixed.
2. As long as the length of the data column in the data table is variable, the length of each data row is also variable.
3. If the length of data rows in a data table is variable, MySQL will convert the fixed-length data columns in this data table into corresponding variable-length data columns in order to save storage space.
Exception: char data columns less than 4 characters in length will not be converted to varchar type.