In an SQL statement, int indicates the type of the field to be created, int indicates the integer type, and 11 indicates the length of the field.
In an SQL statement, int indicates the type of the field to be created, int indicates the integer type, and 11 indicates the length of the field.
This indicates the display width.
The display width of an integer column and the number of characters required to display the value of the column are irrelevant to the size of the storage space required by the integer. For example, no matter how many characters the display width is set, bigint occupies 8 bytes.
Int is an integer, (11) refers to the length of the display characters, but the maximum value is 255, for example, it is the id of the number of records, insert 10 pieces of data, it displays 00000000001 ~~~ 00000000010. When the number of digits of a character exceeds 11, it only displays 11 characters. If you do not add the parameter that causes it to be less than 11 characters, it will not add 0 to the front.
When declaring an integer data column, we can specify a display width M (1 ~ 255), such as INT (5), specifying the display width to 5 characters. If the display width is not specified for it, MySQL will specify a default value for it. The display width is only used for display, and the value range and occupied space cannot be limited. For example, INT (3) occupies 4 bytes of storage space, and the maximum allowed value is not 999, the maximum value allowed by the INT type.
MySQL has five types of Integer Data columns: TINYINT, SMALLINT, MEDIUMINT, INT, and BIGINT. The difference between them is that the value range is different, and the storage space is also different.
Adding the UNSIGNED attribute to the integer data column can disable negative numbers. The value starts from 0.
Int range
Type |
Bytes |
Minimum Value |
Maximum Value |
|
|
(Signed/Unsigned) |
(Signed/Unsigned) |
TINYINT |
1 |
-128 |
127 |
|
|
0 |
255 |
SMALLINT |
2 |
-32768 |
32767 |
|
|
0 |
65535 |
MEDIUMINT |
3 |
-8388608 |
8388607 |
|
|
0 |
16777215 |
INT |
4 |
-2147483648 |
2147483647 |
|
|
0 |
4294967295 |
BIGINT |
8 |
-9223372036854775808 |
9223372036854775807 |
|
|
0 |
18446744073709551615 |
The descriptions on the official website are as follows:
The Code is as follows: |
|
Be careful when considering ENUM ('T', 'F') as "true binary ". Example: Create table 'bits '( 'Val 'enum ('T', 'F') NOT NULL ); Mysql> insert into 'bits '('val') VALUES ('W'), ('T'), ('F '); Query OK, 3 rows affected, 1 warning (0.00 sec) Records: 3 Duplicates: 0 Warnings: 1 Mysql> show warnings; |
+ --------- + ------ + -------------------------------------- + | Level | Code | Message | + --------- + ------ + Warning + | Warning | 1265 | Data truncated for column 'val' at row 1 | + --------- + ------ + ---------------------------------------- + 1 row in set (0.00 sec)
Mysql> select count (DISTINCT val) FROM bits;
+ --------------------- + | COUNT (DISTINCT val) | + --------------------- + | 3 | + --------------------- + 1 row in set (0.00 sec)
Well, shouldn't a binary type have only two distinct values?
(Note that it isn' t NULL .)
Explanation from manual (10.4.4. The ENUM Type ):
-----
If you insert an invalid value into an ENUM (that is, a string not present in the list of permitted values), the empty string is inserted instead as a special error value. this string can be distinguished from a "normal" empty string by the fact that this string has the numeric value 0. more about this later