MySQL int定义说明

多年来,当我为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.

上一篇:java实现连续数的公倍数


下一篇:第九届蓝桥杯试题3--复数幂