The integer types in the MySQL data type is a bit strange. You might see an int data type such as int (3), int (4), int (8). When I first approached MySQL, I thought int (3) took up less storage space than int (4), and int (4) used less storage space than int (8).
Later, see the MySQL manual and find that you understand the mistake.
Int (m): M indicates the maximum display width for integer types.
In the integer data type, M represents the maximum display width.
Originally, in Int (m), the value of M has nothing to do with how much storage space the Int (m) occupies. Int (3), int (4), and Int (8) All occupy 4 btyes of storage space on disk. To put it bluntly, the Int (M) is the same as the int data type except that the way it is displayed to the user is a little different.
In addition,Int (M) can only be combined with Zerofill to make us see the difference clearly.
Mysql> drop table if exists t;mysql> CREATE TABLE t (id int zerofill);mysql> INSERT into T (ID) values; mysql> ; SELECT * FROM t;+------------+| ID |+------------+| 0000000010 |+------------+mysql> ALTER TABLE t change column ID ID int (3) zerofill;mysql> SE Lect * FROM t;+------+| ID |+------+| 010 |+------+mysql>mysql> ALTER TABLE t change column ID ID int. (4) zerofill;mysql> select * FROM t;+------+| ID |+------+| 0010 |+------+mysql>mysql> INSERT INTO T (ID) VALUES (1000000);mysql> select * from t;+-------- -+| ID |+---------+| 0010 | | 1000000 |+---------+
As can be seen from the above test, "(M)" Specifies the width of the int type numeric display, if the field data type is int (4), then: When the value of 10 o'clock is displayed, the left side of the "00", when the value 100 is, on the left to fill "0"; When the value 1000000 is displayed, The specified width "(4)" has been exceeded, so it is output as-is.
When using integer types in MySQL data types (tinyint, smallint, mediumint, Int/integer, bigint), there is no point in adding a "(M)" to the data type after the non-special requirements.
In addition, in MySQL data type , integer and int are synonymous. Which one to use, see for yourself.
What does MySQL data type int (M) mean?