"int"与"int"之间的区别是:和"int(2)"我的SQL中的数据类型 [英] Difference between "int" and "int(2)" data types in my sql

查看:236
本文介绍了"int"与"int"之间的区别是:和"int(2)"我的SQL中的数据类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是想知道为什么范围是用我的sql数据类型给定的.我定义了一个字段名称为"id"且数据类型为"int(2)"的表.我将值作为"123456"插入到字段"id"中.接受并存储了该值.那么给出范围的用途是什么.

Just I wonder why the range is given with the my sql data types. I define a table with a field name "id" and the data type is "int(2)". I inserted the value to the field "id" as "123456".This is accepted and stored. So what is the use of giving the range.

谢谢.

推荐答案

对于INT和其他仅指定显示宽度的数字类型.

For INT and other numeric types that attribute only specifies the display width.

请参见数值类型属性. MySQL文档:

See Numeric Type Attributes in the MySQL documentation:

MySQL支持扩展 可选地指定显示 整数数据类型的宽度 基本关键字后面的括号 对于类型.例如INT(4) 指定一个具有显示宽度的INT 四位数.此可选显示器 宽度可以被应用程序用来 显示具有宽度的整数值 小于指定的宽度 通过用左填充它们来填充列 空格. (也就是说,此宽度为 存在于返回的元数据中 结果集.是否使用 取决于应用程序.)

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

显示宽度不受限制 可以存储的值的范围 在列中.也没有防止 值比列显示宽 宽度无法正确显示. 例如,指定为 SMALLINT(3)具有通常的SMALLINT 范围-32768至32767,以及值 超出三个允许的范围 数字使用完整显示 超过三位数.

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.

这篇关于"int"与"int"之间的区别是:和"int(2)"我的SQL中的数据类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆