为什么我在MySQL中没有设置更大的INT数据类型长度的错误? [英] Why I dont get an error setting larger INT datatype length in MySQL?
问题描述
我对MySql中的数据类型长度有点困惑;我在 http://dev.mysql.com上阅读了参考手册。 /doc/refman/5.0/en/data-types.html 我知道当我写INT(M)...
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表示整数类型的最大显示宽度。对于浮点和定点类型,M是可以存储的总位数。对于字符串类型,M是最大长度。 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.
然后,我在表中添加了一个列,其字段数据类型如INT (10)[未签名]我知道最大值是-2147483648 / 2147483647
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
但是如果我将其编辑为INT(11),MySQL允许我设置虽然长度超出范围但是长度更大而没有任何错误;在这种情况下,我只会在设置一个大于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?
提前谢谢你,
最大
推荐答案
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 in INT(1)
as in INT(30)
. The number does only affect the ZEROFILL
behavior.
mysql> CREATE TEMPORARY TABLE foobar(x INT(40) ZEROFILL);
Query OK, 0 rows affected (0.00 sec)
mysql> INSERT INTO foobar(x) VALUES (42);
Query OK, 1 row affected (0.00 sec)
mysql> SELECT * FROM foobar;
+------------------------------------------+
| x |
+------------------------------------------+
| 0000000000000000000000000000000000000042 |
+------------------------------------------+
1 row in set (0.00 sec)
mysql>
这篇关于为什么我在MySQL中没有设置更大的INT数据类型长度的错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!