+-
mysql – 我的sql中“int”和“int(2)”数据类型的区别
我想知道为什么我的sql数据类型给出了范围.我定义了一个字段名为“id”的表,数据类型为“int(2)”.我将值“id”插入“123456”.这是接受并存储的.那么给出范围有什么用呢?

提前致谢.

最佳答案
对于INT和其他数值类型,该属性仅指定显示宽度.

请参阅MySQL文档中的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.
For example, a column specified as
SMALLINT(3) has the usual SMALLINT
range of -32768 to 32767, and values
outside the range permitted by three
digits are displayed in full using
more than three digits.

点击查看更多相关文章

转载注明原文:mysql – 我的sql中“int”和“int(2)”数据类型的区别 - 乐贴网