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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 14:12:16  来源:igfitidea点击:

What does INT(1) stand for in MySQL?

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 YEARas int(1), I still see all 4 bytes. please tell me what does INT(1)means ?

我已经声明YEARint(1),我仍然看到所有 4 个字节。请告诉我是什么INT(1)意思?

SELECT * FROM TEST_USERDB;
+----+--------+------+
| ID | NAME   | YEAR |
+----+--------+------+
|  1 | abcccc | 2012 |
|  2 | stack  |   99 |
+----+--------+------+

回答by Lion

An unsigned inthas the max value of 4294967295no matter if its INT(1)or int(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)and 0000000000for int(10).

一个无论是 还是unsigned int都有最大值,并且将使用 4 个字节的数据。4294967295INT(1)int(10)

那么,括号中的数字是什么意思呢?它几乎归结为显示,称为显示宽度。显示宽度是一个从 1 到 255 的数字。如果您希望所有整数值都“出现”,您可以设置显示宽度。如果在行上启用 zerofill,则该字段的默认值为 0 forint(1)0000000000for int(10)

Read more

阅读更多