gpt4 book ai didi

MySQL int 定义解释

转载 作者:可可西里 更新时间:2023-11-01 07:54:50 24 4
gpt4 key购买 nike

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

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

最佳答案

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

看看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.

关于MySQL int 定义解释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4332923/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com