转自:http://www.jquerycn.cn/blog/mysql/
那这个int[M]中M是什么意义喃,在定义数值型数据类型的时候,可以在关键字括号内指定整数值(如:int(M),M的最大值为255)显示最大显示宽度,显示宽度M与数据所占用空间,数值的范围无关。 如果在定义字段的时候指定zerofill,那么当数值的显示宽度小于指定的列宽度时候,则默认补充的空格用0代替。
mysql> create table int_12(id int(12) zerofill);
Query OK, 0 rows affected (0.13 sec)
mysql> desc int_12;
+-------+---------------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+---------------------------+------+-----+---------+-------+
| id | int(12) unsigned zerofill | YES | | NULL | |
+-------+---------------------------+------+-----+---------+-------+
1 row in set (0.01 sec)
mysql> insert into int_12 (id) values(1);
Query OK, 1 row affected (0.00 sec)
mysql> select * from int_12;
+--------------+
| id |
+--------------+
| 000000000001 |
+--------------+
1 row in set (0.00 sec)
mysql> alter table int_12 change id id int(23) zerofill;
Query OK, 0 rows affected (0.04 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> select * from int_12 ;
+-------------------------+
| id |
+-------------------------+
| 00000000000000000000001 |
+-------------------------+
1 row in set (0.00 sec)
注意在navicate或者phpmyadmin中显示数据显示可能不正确,如果你加了zerofill,但是没有补充0,可以到mysql命令行中看下