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補充,否則不影響顯示。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM