为什么我在 MySQL 中设置更大的 INT 数据类型长度时没有收到错误消息?
我对 MySql 中的数据类型长度有点困惑;我在 http://dev.mysql.com 阅读了参考手册/doc/refman/5.0/en/data-types.html 我知道当我写“INT(M)”时...
M表示整数类型的最大显示宽度。对于浮点和定点类型,M 是可以存储的总位数。对于字符串类型,M 是最大长度。 M 的最大允许值取决于数据类型。
然后,我在表中添加了一列,其字段数据类型如 INT(10) [not unsigned],我知道最大值是 -2147483648 / 2147483647
但是,如果我将其编辑为 INT(11),MySQL 允许我设置尽管长度超出范围,但没有任何误差的较大长度;在这种情况下,只有当我设置的值大于 2147483647 时才会出现错误,为什么之前不呢?
提前谢谢你,
马克斯
I'm a little bit confused on datatypes length in MySql; I read the reference manual at http://dev.mysql.com/doc/refman/5.0/en/data-types.html and I know that when I write "INT(M)"...
M indicates the maximum display width for integer types. For floating-point and fixed-point types, M is the total number of digits that can be stored. For string types, M is the maximum length. The maximum permissible value of M depends on the data type.
Then, I added a column to my table with a field datatype like INT(10) [not unsigned] and I know that the maximum values are -2147483648 / 2147483647
However if I edit it to INT(11), MySQL permit me to set a larger length without any error although the length is out of the range; in this case, I'll get an error only when I set a value larger of 2147483647, why not before?
Thank You in advance,
Max
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
M
值不会影响您可以存储的数字范围。您可以在INT(1)
中保存与INT(30)
中相同的数字。该数字仅影响ZEROFILL
行为。The
M
value doesn't affect the range of numbers you can store. You can save the same numbers inINT(1)
as inINT(30)
. The number does only affect theZEROFILL
behavior.我只能推测,但我的猜测是显示宽度设置不够智能,无法识别冲突。但无论如何,由于显示宽度只是客户端程序的一个建议,我认为不一定如此。
I can only speculate, but my guess is that the display width setting just isn't smart enough to recognize the conflict. But seeing as the display width is just a recommendation for client programs anyway, I would argue it doesn't have to be.