mysql int 字段不截断
众所周知,当您描述 varchar 或整数字段时,您应该设置它们的长度...
类似 int(5) 或 varchar(5)...
但是当您尝试将 123456 添加到这两个字段时...而 varchar 字段截断值,整数字段不会截断它......
那么描述 int 长度的目的是什么?
as all you know, when you describe varchar or integer fields you should set the length of them...
something like int(5) or varchar(5)...
but when you try add 123456 to both fields.. while varchar field truncates the value, integer field does not truncate it...
so what's the aim of describing int length?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
看来这个“长度”仅用于显示: http:// /dev.mysql.com/doc/refman/5.0/en/numeric-types.html
It appears this "length" is used for display only: http://dev.mysql.com/doc/refman/5.0/en/numeric-types.html
INT 类型的大小既不是位也不是字节。这只是当字段指定了 ZEROFILL 时使用的显示宽度。
请参阅这篇博客文章 进行深入解释。
The size of the INT type is neither bits nor bytes. It's just the display width that is used when the field has ZEROFILL specified.
See this blog article for an in depth explanation.
从 10.2 开始。数字类型
FRom 10.2. Numeric Types
int(5)
并不像您想象的那样:它指定一个显示宽度为 5 位数字的整数字段,即小于 5 位数字的数字将被填充空格字符。在 MySQL 中,
int
值始终为 4 字节宽,范围为 -2,147,483,648 到 2,147,483,647。请参阅http://dev.mysql.com/doc/refman/ 5.0/en/numeric-types.html。
int(5)
does not do what you think it does: it specifies an integer field with a display width of 5 digits, i.e. numbers shorter than 5 digits will be padded with space characters.In MySQL,
int
values are always 4 bytes wide and can go from -2,147,483,648 to 2,147,483,647.See http://dev.mysql.com/doc/refman/5.0/en/numeric-types.html.
INT(N)
中的N
,表示应用程序显示长度;由于语法与VARCHAR(N)
相似,这是非常具有误导性的,并且可以理解,经常被误解。对于我见过的所有应用程序来说,它实际上毫无意义。这适用于所有
TINYINT
、SMALLINT
、MEDIUMINT
、INT
、BIGINT
。The
N
inINT(N)
, indicating application display length; is was very misleading, due to the syntax similarity toVARCHAR(N)
, and understandably, often misunderstood. It's effectively meaningless for all applications I've seen.This goes for all
TINYINT
,SMALLINT
,MEDIUMINT
,INT
,BIGINT
.