int(11) 与 int(其他任何东西)
我是网络编程的新手,正在做我可以在网上找到的不同教程.
I'm new to web programming and doing different tutorials that I can find on the net.
我做了我的研究,发现在 int(11) 中,11 是整数的最大显示宽度,除非整数是 UNSIGNED(在本例中为 10),否则它是默认值.
I did my research and found out that in int(11), 11 is the maximum display width for integers and it's the default value if unless the integer is UNSIGNED (in this case it's 10).
当我看到这样的事情时:
When I see something like this:
id INT(11) not null AUTO_INCREMENT
我没有问题.但是为什么我在不同的教程中看到不同的东西?例如,在某些情况下,它说,
I have no questions. But why do I see different things in different tutorials? For examlpe, in some, it says,
id INT(10) not null AUTO_INCREMENT
甚至
id INT(4) not null AUTO_INCREMENT
那些 tuts 的作者想达到什么目的?他们似乎都懒得解释 10 或 4 的含义.
What are the authors of those tuts trying to achieve? None of them seem to bother to give an explanation what 10 or 4 means.
好吧,他们显然在减少显示宽度,但为什么呢?默认宽度 11 有什么问题?他们为什么要改变它?或者还有其他我不知道的原因吗?
Alright, they're obviously reducing the display width, but why? What's wrong with the default width of 11? Why would they want to change it? Or are there any other reasons I don't know of?
谢谢.
推荐答案
INT(x)
中的 x
与空间要求或任何其他性能问题无关,它实际上只是显示宽度.通常,使用 UNSIGNED ZEROFILL
选项将显示宽度设置为合理的值最有用.
The x
in INT(x)
has nothing to do with space requirements or any other performance issues, it's really just the display width. Generally setting the display widths to a reasonable value is mostly useful with the UNSIGNED ZEROFILL
option.
//INT(4) UNSIGNED ZEROFILL
0001
0002
...
0099
...
0999
...
9999
...
10000
//INT(2) UNSIGNED ZEROFILL
01
02
...
09
...
99
...
100
如果没有 UNSIGNED ZEROFILL
选项,该值将用空格左填充到适当的显示宽度.
Without the UNSIGNED ZEROFILL
option the value will be left-padded with spaces to the appropriate display width.
//INT(4)
1
2
...
99
...
999
...
9999
...
10000
//INT(2)
1
2
...
9
...
99
...
100
相关文章