int[(M)] [UNSIGNED] [Zerofill]
An integer of normal size. The signed range is 2147483648 to 2147483647. The unsigned range is 0 to 4294967295.
Int (1) and int (10) have no difference in themselves, but with the (M) value, there will be a display width setting.
As shown in the code:
Mysql> CREATE TABLE test (ID int (3)); Query OK, 0 rows affected (0.47 sec) mysql> insert into test values (12); Query OK, 1 row affected (0.12 sec) mysql> insert into test values (1234); Query OK, 1 row affected (0.10 sec) mysql> SELECT * FROM test;+------+| ID |+------+| 12 | | 1234 |+------+
Try again. Let's add the Zerofill.
Mysql> CREATE TABLE test1 (ID int (3) zerofill); Query OK, 0 rows affected (0.32 sec) mysql> INSERT into Test1 value (12); Query OK, 1 row affected (0.07 sec) mysql> insert into Test1 value (1234); Query OK, 1 row affected (0.05 sec) mysql> select * FROM test1;+------+| ID |+------+| 012 | | 1234 |+------+
Note that the 12 front output is more than a 0,int (M) value more than 0, which is the limit of the display width. And more out of it will show up. Only the system to determine the 12 display width is insufficient, will fill the total display width
But be careful when inserting negative numbers:
Negative number is displayed when Zerofill is not set
mysql> INSERT into Test value (-1234); Query OK, 1 row affected (0.07 sec) mysql> select * from test;+-------+| ID |+-------+| | | 123 | | -1234 |+-------+3 rows in Set (0.00 sec)
Let's take a look at setting Zerofill:
mysql> INSERT into Test1 value (-1234); Query OK, 1 row affected, 1 warning (0.11 sec) mysql> select * FROM test1;+------+| ID |+------+| 012 | | 1234 | | |+------+
The output is 000, and the insertion is-1234. The display is 000.
Originally added Zerofill when the system will automatically add the unsigned property. is a non-negative number. The display width is set to 3 bits. So it will output 000.
The difference between an int (1) and an int (10) in MySQL