MySQL BigInt(20) 和 Int(20) 之间的区别?
mysqlmysqli database
int 类型采用 4 字节有符号整数,即 32 位(可存储 232 个值)。BigInt 类型采用 8 字节有符号整数,即 64 位(可存储 264 个值)。
让我们看一个例子。
创建一个带有零填充的表,它将添加前导零。
mysql> create table IntandBigint20Demo -> ( -> Number int(20) zerofill, -> Code BigInt(20) zerofill -> ); Query OK, 0 rows affected (0.58 sec)
创建表后,我们将向表中插入记录。
mysql> insert into IntandBigint20Demo values(987,987); Query OK, 1 row affected (0.16 sec)
现在我们可以借助 select 语句显示所有记录。查询如下 −
mysql> select *from IntandBigint20Demo;
以下是输出。
+----------------------+----------------------+ | Number | Code | +----------------------+----------------------+ | 00000000000000000987 | 00000000000000000987 | +----------------------+----------------------+ 1 row in set (0.00 sec)
查看示例输出,一开始填充的是 0。这本身就表明宽度为 20。
Number int(20) zerofill