MySQL int 定义解释

发布于 2024-10-05 18:34:34 字数 171 浏览 0 评论 0原文

多年来,当我为 MySQL 表创建 bigint(12) 类型的新列时,我一直假设该字段仅限于最多 12 位的整数。然而,我最近注意到,可以在 bigint(12) 定义的列中写入和选择最多 16 位数字的值,而不会出现任何警告或问题。

有人可以帮助我理解为什么会出现这种情况以及该列定义的实际含义吗?提前致谢!

For years I have been under the assumption when I create a new column of type bigint(12) for a MySQL table that the field is limited to integers with up to 12 digits. However, I recently noticed that values up to 16 digits are able to be written into and selected out of a bigint(12) defined column without any warnings or issues.

Can someone please help me understand why this is the case and what that column definition actually means? Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

羁〃客ぐ 2024-10-12 18:34:34

bigint(12) 根本没有被截断。 12 用于显示目的。

查看数字类型

数字类型属性

MySQL 支持以下扩展:
可选地指定显示
整数数据类型的宽度
基本关键字后面的括号
对于类型。例如,INT(4)
指定具有显示宽度的 INT
四位数字。此可选显示
应用程序可以使用宽度来
显示具有宽度的整数值
小于指定的宽度
向左填充列
空间。 (也就是说,这个宽度是
存在于返回的元数据中
结果集。不管用还是没用
取决于应用程序。)

显示宽度不限制可以存储的值的范围
在专栏中。也不能阻止
值比列显示宽
宽度无法正确显示。

bigint(12) is not truncated at all. The 12 is used for display purposes.

Have a look at Numeric Types

Numeric Type Attributes

MySQL supports an extension for
optionally specifying the display
width of integer data types in
parentheses following the base keyword
for the type. For example, INT(4)
specifies an INT with a display width
of four digits. This optional display
width may be used by applications to
display integer values having a width
less than the width specified for the
column by left-padding them with
spaces. (That is, this width is
present in the metadata returned with
result sets. Whether it is used or not
is up to the application.)

The display width does not constrain the range of values that can be stored
in the column. Nor does it prevent
values wider than the column display
width from being displayed correctly.

简美 2024-10-12 18:34:34

阅读 MySql 文档中的数字类型属性部分 INT(4)指定显示宽度为四位的INT

read Numeric Type Attributes section from MySql documentation INT(4) specifies an INT with a display width of four digits

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文