INT(1) 在 MySQL 中代表什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11563830/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What does INT(1) stand for in MySQL?
提问by chicharito
INT(1)
- I know, 1 does not mean 1 digit, it represents client output display format only.
INT(1)
- 我知道,1 不代表 1 位数字,它仅代表客户端输出显示格式。
but what does this signify
但这意味着什么
i have declared YEAR
as int(1)
, I still see all 4 bytes. please tell me what does INT(1)
means ?
我已经声明YEAR
为int(1)
,我仍然看到所有 4 个字节。请告诉我是什么INT(1)
意思?
SELECT * FROM TEST_USERDB;
+----+--------+------+
| ID | NAME | YEAR |
+----+--------+------+
| 1 | abcccc | 2012 |
| 2 | stack | 99 |
+----+--------+------+
回答by Lion
An
unsigned int
has the max value of4294967295
no matter if itsINT(1)
orint(10)
and will use 4 bytes of data.So, what does the number in the brackets mean? It pretty much comes down to display, its called the display-width. The display width is a number from 1 to 255. You can set the display width if you want all of your integer values to “appear”. If you enable zerofill on the row, the field will have a default value of 0 for
int(1)
and0000000000
forint(10)
.
一个无论是 还是
unsigned int
都有最大值,并且将使用 4 个字节的数据。4294967295
INT(1)
int(10)
那么,括号中的数字是什么意思呢?它几乎归结为显示,称为显示宽度。显示宽度是一个从 1 到 255 的数字。如果您希望所有整数值都“出现”,您可以设置显示宽度。如果在行上启用 zerofill,则该字段的默认值为 0 for
int(1)
和0000000000
forint(10)
。