我使用 mysql 创建了两个字段 text(varchar)
, number(int)
。但我不确定我应该为 varchar()
、int()
和 varchar()
设置什么大小,我在这里检查过:http://dev.mysql.com/doc/refman/5.0/en/char.html ,并且知道如果我输入 varchar(4)
,这意味着:最多可以容纳 4 个字符。但是对于int(4)
,我这里查了:http://dev.mysql.com/doc/refman/5.0/en/integer-types.html,据说是:Maximum Value:(Signed/Unsigned)(2147483647/4294967295)
问题:
对于int(4)
,它是如何得到这个值2147483647/4294967295
的?如果我输入 int(8)
,值会是多少?
最佳答案
See the MySQL Numeric Type Documentation .这些事情都有据可查。
The range for a signed
INT
is [-2147483648, 2147483647].Note that in the case of
INT(x)
, x is the "display width" and has nothing to do with the range or space requirements: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 ... display width does not constrain [or expand] the range of values that can be stored in the column.
关于mysql:int 类型的最大值问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18310742/