1 Introduction
Integer type, the integer type, MySQL supports the integer types TINYINT, SMALLINT, MEDIUMINT, INT, BIGINT.
1.1 space and scope
And the storage space required for each range of integer types as follows:
类型 |
byte | Minimum (Signed) |
Maximum (Signed) |
Minimum (Unsigned) |
Maximum (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 |
|
|
0 |
|
2. INT(11)
2.1 Digital whether to limit the length?
id INT(11) NOT NULL AUTO_INCREMENT,
Some types of construction of the table in the statement will appear above int (11), then what does it mean?
It referred to the field of type Integer number in parentheses display width . This is different from the meaning of other types of fields. For DECIMAL types, it represents the total number of numbers. For character field, which is the maximum number of characters that can be stored, for example, VARCHAR (20) can store 20 characters.
The maximum width does not affect the display can be stored in that column. INT (5), and INT (11) can store the same maximum value. Even arranged INT (20 is) not intended to be able to store 20 digits (BIGINT), or only the maximum value INT stored in the column.
Examples
Create a temporary table:
CREATE TEMPORARY TABLE demo_a ( id INT(11) NOT NULL AUTO_INCREMENT, a INT(1) NOT NULL, b INT(5) NOT NULL, PRIMARY KEY (`id`) )
Insert more than the "length" of the figures:
INSERT INTO demo_a(a,b) VALUES(255, 88888888);
View Results: The number is not set length
mysql> SELECT * FROM demo_a; +----+-----+----------+ | id | a | b | +----+-----+----------+ | 1 | 255 | 88888888 | +----+-----+----------+ 1 row in set (0.03 sec)
2.2 Digital express what does that mean?
When the column is set to UNSIGNED ZEROFILL time, INT (11) makes sense, meaning it represents as a digital If you want to store fewer than 11 characters, then these figures will be padded with zeros on the left.
Note : ZEROFILL default as unsigned, and therefore can not store negative numbers.
Examples
Create a temporary table: b column is set to UNSIGNED ZEROFILL
CREATE TEMPORARY TABLE demo_a ( id INT(11) NOT NULL AUTO_INCREMENT, a INT(11) NOT NULL, b INT(11) UNSIGNED ZEROFILL NOT NULL, PRIMARY KEY (`id`) );
Insert values:
INSERT INTO demo_a(a,b) VALUES(1, 1);
Results: left column using a 0 b stuffing length
mysql> SELECT * FROM demo_a; +----+---+-------------+ | id | a | b | +----+---+-------------+ | 1 | 1 | 00000000001 | +----+---+-------------+ 1 row in set (0.18 sec)
3. References
Integer type : https://dev.mysql.com/doc/refman/5.6/en/integer-types.html
What does int(11) means in MySQL?:https://www.virendrachandak.com/techtalk/mysql-int11-what-does-it-means/