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补充,否则不影响显示。

(转载来源)https://www.cnblogs.com/mysql-dba/p/5197736.html

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值