INTM表示什么意思

根据官方文档描述,int(M)中的M表示数据显示的宽度,与实际存储的长度无关。

1、也就是int(3)和int(11)能够存储的数据是一样的,都是从-21474836482147483647(或者0-4294967295)。

2、int(M)只有联合zerofill参数才能有意义,否则int(3)和int(11)没有任何区别。

下面用实例来证明上述两句话:

1、创建测试表,具有int(3)、int(11)、int三个字段

create table test_intid int3) unsigned not null,uid int11) unsigned not null,uuid int unsigned not null );

下面插入int无符号能够存储的最大值:

insert into test_int values4294967295,4294967295,4294967295);

product)root@localhost [a]> select * from test_int;
+------------+------------+------------+
| id         | uid        | uuid       |
+------------+------------+------------+
| 4294967295 | 4294967295 | 4294967295 |
+------------+------------+------------+
1 row in set 0.00 sec)

【结论1】通过上述实验,对于没有加上zerofill参数的int、int(3)、int(11)无论在存储上还是在显示上都毫无区别。

2、创建测试表,具有int(3)、int(11)、int三个字段同时加上zerofill参数

product)root@localhost [a]> create table test_int1id int3) unsigned zerofill not null,uid int11) unsigned zerofill not null,uuid int unsigned zerofill not null );
Query OK, 0 rows affected 0.14 sec)

product)root@localhost [a]> insert into test_int1 values4294967295,4294967295,4294967295);
Query OK, 1 row affected 0.03 sec)

product)root@localhost [a]> insert into test_int1 values1,4294967295,110000);
Query OK, 1 row affected 0.00 sec)

product)root@localhost [a]> select * from test_int1;
+------------+-------------+------------+
| id         | uid         | uuid       |
+------------+-------------+------------+
| 4294967295 | 04294967295 | 4294967295 |
|        001 | 04294967295 | 0000110000 |
+------------+-------------+------------+
2 rows in set 0.00 sec)

【结论2】通过上述实验,对于加上zerofill参数的int、int(3)、int(11),不足M宽度的,用0补充,否则不影响显示。

Published by

风君子

独自遨游何稽首 揭天掀地慰生平