300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > INT(M)表示什么意思?

INT(M)表示什么意思?

时间:2023-05-30 20:37:18

相关推荐

INT(M)表示什么意思?

根据官方文档描述,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_int(id int(3) unsigned not null,uid int(11) unsigned not null,uuid int unsigned not null );

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

insert into test_int values(4294967295,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_int1(id int(3) unsigned zerofill not null,uid int(11) 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 values(4294967295,4294967295,4294967295);Query OK, 1 row affected (0.03 sec)(product)root@localhost [a]> insert into test_int1 values(1,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补充,否则不影响显示。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。