日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

mysql int zerofill_Mysql 中int[M]—zerofill-阿里云开发者社区

發布時間:2025/3/21 数据库 19 豆豆
生活随笔 收集整理的這篇文章主要介紹了 mysql int zerofill_Mysql 中int[M]—zerofill-阿里云开发者社区 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

我們在定義數字類型的數據類型的時候,往往考慮該數字類型的數據能否裝的下該字段的最大值,如狀態位的字段:tinyint,表的主鍵:int,或者bigint,今天在看到開發同學提交表結構設計文檔中看到數值類型的字段定義為int(255),int(20),int(2)當時一下還沒有反映過來,我們知道在mysql中數字類型用定長字節存儲:

Column Type

Bytes On Disk

tinyint

1 bytes

smallint

2 bytes

mediumint

3 bytes

int

4 bytes

bigint

8 bytes

估計他們這樣定義是想為了存儲更多范圍的數據;

那這個int[M]中M是什么意義喃,在定義數值型數據類型的時候,可以在關鍵字括號內指定整數值(如:int(M),M的最大值為255)顯示最大顯示寬度,顯示寬度M與數據所占用空間,數值的范圍無關。 如果在定義字段的時候指定zerofill,那么當數值的顯示寬度小于指定的列寬度時候,則默認補充的空格用0代替。

Zerofill: root@test 10:24:26>create table int_12(id int(12) zerofill);

Query OK, 0 rows affected (0.11 sec)

root@test 10:28:07>insert into int_12 values(1);

Query OK, 1 row affected (0.00 sec)

root@test 10:28:18>select * from int_12;

+————–+

| id?????????? |

+————–+

| 000000000001 |

+————–+

1 row in set (0.00 sec)

Nozerofill:

root@test 11:13:31>desc int_12_no;

+——-+———+——+—–+———+——-+

| Field | Type??? | Null | Key | Default | Extra |

+——-+———+——+—–+———+——-+

| id??? | int(12) | YES? |???? | NULL??? |?????? |

root@test 11:14:16>insert into int_12_no values(1);

Query OK, 1 row affected (0.00 sec)

root@test 11:14:32>select * from int_12_no;

+——+

| id?? |

+——+

|??? 1 |

+——+

1 row in set (0.00 sec)

存儲結構:

root@test 11:14:38>select id,hex(id) from int_12_no;

+——+———+

| id?? | hex(id) |

+——+———+

|??? 1 | 1?????? |

+——+———+

1 row in set (0.00 sec)

root@test 11:15:17>select id,hex(id) from int_12;

+————–+———+

| id?????????? | hex(id) |

+————–+———+

| 000000000001 | 1?????? |

+————–+———+

1 row in set (0.00 sec)

可以看到通過hex函數導出內部的存儲結構是一樣的,所以占用的空間大小是相同的;

數值范圍:

root@test 11:17:42>create table test_4(id int(4) zerofill);

Query OK, 0 rows affected (0.12 sec)

root@test 11:18:17>insert into test_4 values(12345);

Query OK, 1 row affected (0.00 sec)

root@test 11:18:29>select * from test_4;

+——-+

| id??? |

+——-+

| 12345 |

+——-+

1 row in set (0.00 sec)

可以看到,當數值的范圍超過指定顯示范圍后,并沒有出現截斷的情況。

總結

以上是生活随笔為你收集整理的mysql int zerofill_Mysql 中int[M]—zerofill-阿里云开发者社区的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。