The integer type is followed by the width of the display. m indicates the maximum display width. The maximum effective display width is 255. The display width is independent of the range of values that the storage size or type contains.
To practice the truth:
Mysql> CREATE TABLE test2 (a int, b int (unsigned) not NULL, C int (+) unsigned zerofill) engine = InnoDB;
Query OK, 0 rows affected (0.06 sec)
Mysql> Show CREATE TABLE test2;
+-------+------------------------------------- --------------------------------------------------------------------------------------------------------------- -------------------+
| Table | Create Table |
+-------+------------------------------------------------------------------------------------------------------ -----------------------------------------------------------------+
| Test2 | CREATE TABLE ' Test2 ' (
' A ' int (one) DEFAULT NULL,
' B ' int (unsigned) is not NULL,
' C ' int (+) unsigned zerofill DEFAULT NULL
) Engine=innodb DEFAULT Charset=utf8 |
Inserts a record into a table.
mysql> INSERT INTO test2 values (1, 2000000, 34823424);
Query OK, 1 row affected (0.04 sec)
Mysql> select * from Test2;
+------+---------+------------------------------------------+
| A | B | C |
+------+---------+------------------------------------------+
| 1 | 2000000 | 0000000000000000000000000000000034823424 |
+------+---------+------------------------------------------+
Mysql> ALTER TABLE test2 add d int (n) not null;
ERROR 1439 (42000): Display width out of range for column ' d ' (max = 255)
From the above test can be described below:
1: For shaping data types, the number of bytes that the data store occupies is fixed-length. Like what
int[(M)] [UNSIGNED] [Zerofill].
which
m indicates the maximum display width. The maximum effective display width is 255. When the inserted table's field data length is less than the maximum length of the set int (M), the retrieved data is automatically added to the space.
2:zerofill (0), when the actual length of the inserted data is less than the length set when the table is built, it will be 0 from the left. This modifier can prevent MySQL from storing negative values.
3: When the table is built, do not specify the display length of int, the system will automatically preset the display length size.
MySQL integer type description int (one) vs int ()