MySQL 中 int(5) 與 int(10) 的區別?
括號中的值用於僅顯示寬度並設定零填充。對於 int(5),寬度為 5,而對於 int(10),寬度為 10。我們來看看另一個設定了不同寬度值的 int 示例。
讓我們先建立一個表。在此,我們將 int 設定為 int(11) 和 int(13)。以下是建立表的查詢 −
mysql> create table intVsIntAnyThingDemo −> ( −> Number1 int(11) unsigned zerofill, −> Number int(13) unsigned zerofill −> ); Query OK, 0 rows affected (1.17 sec)
現在,你可以使用 insert 命令在表中插入記錄。查詢如下 −
mysql> insert into intVsIntAnyThingDemo values(12345,6789); Query OK, 1 row affected (0.44 sec) mysql> insert into intVsIntAnyThingDemo values(3,2); Query OK, 1 row affected (0.20 sec) mysql> insert into intVsIntAnyThingDemo values(12,89); Query OK, 1 row affected (0.15 sec) mysql> insert into intVsIntAnyThingDemo values(123,6789); Query OK, 1 row affected (0.17 sec) mysql> insert into intVsIntAnyThingDemo values(1234,6789); Query OK, 1 row affected (0.14 sec)
使用 select 語句顯示所有記錄。查詢如下 −
mysql> select *from intVsIntAnyThingDemo;
以下是為 int 設定的總寬度顯示零填充的輸出 −
+-------------+---------------+ | Number1 | Number | +-------------+---------------+ | 00000012345 | 0000000006789 | | 00000000003 | 0000000000002 | | 00000000012 | 0000000000089 | | 00000000123 | 0000000006789 | | 00000001234 | 0000000006789 | +-------------+---------------+ 5 rows in set (0.00 sec)
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP