int(11)与int(其他) [英] int(11) vs. int(anything else)

查看:75
本文介绍了int(11)与int(其他)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Web编程的新手,正在做可以在网上找到的各种教程.

I'm new to web programming and doing different tutorials that I can find on the net.

我做了研究,发现在int(11)中,11是整数的最大显示宽度,如果整数未签名则为默认值(在本例中为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

这些tut的作者试图达到什么目的?他们似乎都不想去解释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

这篇关于int(11)与int(其他)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆