MySQL INT(7) 是什么意思?
在 INT(7) 中,数字表示显示的宽度。它不会影响存储,因为我们知道 int 占用 4 字节。它的范围在 -2147483648 到 2147483647 之间。
为了理解 INT(7),我们可以创建一个带有 zerofill 列的表。创建表的查询如下所示 −
mysql> create table DisplayInt
-> (
-> Number int(7) zerofill
-> );
Query OK, 0 rows affected (1.25 sec)
使用 insert 命令将一些记录插入表中。插入查询如下所示 −
mysql> insert into DisplayInt values(1);
Query OK, 1 row affected (0.12 sec)
mysql> insert into DisplayInt values(12);
Query OK, 1 row affected (0.16 sec)
mysql> insert into DisplayInt values(1234);
Query OK, 1 row affected (0.19 sec)
mysql> insert into DisplayInt values(12345);
Query OK, 1 row affected (0.10 sec)
mysql> insert into DisplayInt values(1234567);
Query OK, 1 row affected (0.18 sec)
使用 select 语句从表中显示所有记录。查询如下所示。
mysql> select *from DisplayInt;
以下是输出结果。
+--------+
| Number |
+--------+
| 0000001 |
| 0000012 |
| 0001234 |
| 0012345 |
| 1234567 |
+--------+
5 rows in set (0.00 sec)
阅读更多:MySQL 教程
极客教程