mysql中 int(M)中M

http://dev.mysql.com/doc/refman/5.0/en/numeric-type-overview.html

  这个M 就是maximum display width。那什么是maximum display width?看了下面的例子很容易说明了,注意zerofill

 

 mysql> create table b ( b int (4));
Query OK, 0 rows affected (0.25 sec)

mysql> insert into b values (12345);
Query OK, 1 row affected (0.00 sec)

mysql> select * from b;
+-------+
| b     |
+-------+
| 12345 |
+-------+
1 row in set (0.00 sec)

mysql> alter table b change b b int(11);
Query OK, 1 row affected (0.00 sec)
Records: 1  Duplicates: 0  Warnings: 0

mysql> select * from b;
+-------+
| b     |
+-------+
|
12345 |
+-------+
1 row in set (0.00 sec)

mysql> alter table b change b b int(11) zerofill;
Query OK, 1 row affected (0.00 sec)
Records: 1  Duplicates: 0  Warnings: 0

mysql> select * from b ;
+-------------+
| b           |
+-------------+
| 000000
12345 |
+-------------+
1 row in set (0.00 sec)

mysql> alter table b change b b int(4) zerofill;
Query OK, 1 row affected (0.08 sec)
Records: 1  Duplicates: 0  Warnings: 0

mysql> select * from b ;
+-------+
| b     |
+-------+
| 10000 |
+-------+
1 row in set (0.00 sec)

mysql> alter table b change b b int(6) zerofill;
Query OK, 1 row affected (0.01 sec)
Records: 1  Duplicates: 0  Warnings: 0

mysql> select * from b;
+--------+
| b      |
+--------+
| 0
12345 |
+--------+
1 row in set (0.00 sec)

     以上的例子说明了,这个M的表示显示宽度,他跟着zerofill 一起才有意义。就算前面设置的M的值比数值实际的长度小对数据也没有任何影响。

mysql中 int(M)中M,布布扣,bubuko.com

mysql中 int(M)中M

上一篇:SQLServer清空表


下一篇:sql去除重复语句