Types in MySQL: BigInt(20) vs Int(20)(MySQL 中的类型:BigInt(20) 与 Int(20))
问题描述
我想知道 BigInt
、MediumInt
和 Int
之间的区别...更大的数字;但是,我可以制作一个 Int(20)
或一个 BigInt(20)
并且看起来它不一定与大小有关.
I was wondering what the difference between BigInt
, MediumInt
, and Int
are... it would seem obvious that they would allow for larger numbers; however, I can make an Int(20)
or a BigInt(20)
and that would make seem that it is not necessarily about size.
一些见解会很棒,只是有点好奇.我一直在使用 MySQL 一段时间,并在选择类型时尝试应用业务需求,但我从未理解这方面.
Some insight would be awesome, just kind of curious. I have been using MySQL for a while and trying to apply business needs when choosing types, but I never understood this aspect.
推荐答案
参见 http://dev.mysql.com/doc/refman/8.0/en/numeric-types.html
INT
是一个四字节的有符号整数.
INT
is a four-byte signed integer.
BIGINT
是一个八字节的有符号整数.
BIGINT
is an eight-byte signed integer.
它们每个接受的值都不能多于可以存储在各自字节数中的值.这意味着 INT
中有 232 个值,BIGINT
中有 264 个值.
They each accept no more and no fewer values than can be stored in their respective number of bytes. That means 232 values in an INT
and 264 values in a BIGINT
.
INT(20)
和 BIGINT(20)
中的 20 几乎没有任何意义.这是显示宽度的提示.它与存储无关,也与列将接受的值范围无关.
The 20 in INT(20)
and BIGINT(20)
means almost nothing. It's a hint for display width. It has nothing to do with storage, nor the range of values that column will accept.
实际上,它只影响 ZEROFILL
选项:
Practically, it affects only the ZEROFILL
option:
CREATE TABLE foo ( bar INT(20) ZEROFILL );
INSERT INTO foo (bar) VALUES (1234);
SELECT bar from foo;
+----------------------+
| bar |
+----------------------+
| 00000000000000001234 |
+----------------------+
对于 MySQL 用户来说,看到 INT(20)
并假设它是一个大小限制,类似于 CHAR(20)
,这是一个常见的混淆源.事实并非如此.
It's a common source of confusion for MySQL users to see INT(20)
and assume it's a size limit, something analogous to CHAR(20)
. This is not the case.
这篇关于MySQL 中的类型:BigInt(20) 与 Int(20)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:MySQL 中的类型:BigInt(20) 与 Int(20)
- 使用 Oracle PL/SQL developer 生成测试数据 2021-01-01
- 在SQL中,如何为每个组选择前2行 2021-01-01
- 远程 mySQL 连接抛出“无法使用旧的不安全身份验证连接到 MySQL 4.1+"来自 XAMPP 的错误 2022-01-01
- 更改自动增量起始编号? 2021-01-01
- 如何使用 pip 安装 Python MySQLdb 模块? 2021-01-01
- 导入具有可变标题的 Excel 文件 2021-01-01
- 如何将 Byte[] 插入 SQL Server VARBINARY 列 2021-01-01
- 以一个值为轴心,但将一行上的数据按另一行分组? 2022-01-01
- 如何将 SonarQube 6.7 从 MySQL 迁移到 postgresql 2022-01-01
- SQL 临时表问题 2022-01-01