INT(M)表示什么意思?
生活随笔
收集整理的這篇文章主要介紹了
INT(M)表示什么意思?
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
根據官方文檔描述,int(M)中的M表示數據顯示的寬度,與實際存儲的長度無關。
1、也就是int(3)和int(11)能夠存儲的數據是一樣的,都是從-2147483648到2147483647(或者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
總結
以上是生活随笔為你收集整理的INT(M)表示什么意思?的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: redis/分布式文件存储系统/数据库
- 下一篇: HDU 4602 - Partition