MySQL 中 tinyint(2) 的最大值是多少?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3939882/
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 is maximum value for tinyint(2) in MySQL?
提问by user476554
What is the maximum value allowed for a column of type tinyint(2)
?
类型的列允许的最大值是tinyint(2)
多少?
Are values like 255 or 99 allowed? I am confused because (2)
after tinyint(2)
denotes only the display... Am I correct?
是否允许使用 255 或 99 之类的值?我很困惑,因为(2)
aftertinyint(2)
仅表示显示...我正确吗?
回答by
It takes 127.
需要 127。
refer link : http://dev.mysql.com/doc/refman/5.1/en/numeric-types.html
参考链接:http: //dev.mysql.com/doc/refman/5.1/en/numeric-types.html
回答by user476554
MySQL 5.0 Reference Manual: Numeric Types
The display width does not constrain the range of values that can be stored in the column. Nor does it prevent values wider than the column display width from being displayed correctly.
显示宽度不限制可以存储在列中的值的范围。它也不会阻止比列显示宽度更宽的值正确显示。
Edit:No. Note that UNSIGNED
is a non-standard attribute that affects the range. Neither value given in your question is the correct upper-limit of a normalTINYINT(2)
.
编辑:否。请注意,这UNSIGNED
是影响范围的非标准属性。您的问题中给出的值都不是正常TINYINT(2)
.
Edit for the comment edit:Trust the documentation unless there is a reason not to. If something seems fishy, TIAS (try it and see).
编辑评论编辑:相信文档,除非有理由不这样做。如果有些东西看起来很可疑,TIAS(试试看)。
回答by MSD
For tinyint data type:
if db column is SIGNED : min:-128 , max:127
if db column is UNSIGNED : min:0 , max:255
Just this.
more help! :
http://dev.mysql.com/doc/refman/5.1/en/integer-types.html
对于 tinyint 数据类型:
如果 db 列是 SIGNED : min:-128 , max:127
如果 db 列是 UNSIGNED : min:0 , max:255
就是这个。
更多帮助!:http:
//dev.mysql.com/doc/refman/5.1/en/integer-types.html
回答by kakubei
I believe the correct answer to this question is:
我相信这个问题的正确答案是:
255
not 127.
不是 127。
Check this page out: Mysql Integer types
查看此页面:Mysql 整数类型
What other answers are failing to tell you is that the maximum can be 255 if you don't use negative numbers.
其他答案没有告诉您的是,如果您不使用负数,最大值可以是 255。
If you're using negative numbers then the maximum value can only be 127.
如果您使用负数,则最大值只能为 127。
That's really what the unsigned
and signed
words mean, unfortunately no one explained this to you so I can see why it's confusing.
这就是unsigned
和signed
词的真正含义,不幸的是没有人向您解释这一点,所以我明白为什么它令人困惑。
usigned
means it cannot contain negative numbers so if you set your column to be unsigned
then you can use 255
as the maximum. If you don't explicitly set the column as unsigned
it means it will accept negative numbers (thus being a signed
column) in which case the maximum will now be 127
.
usigned
意味着它不能包含负数,因此如果您将列设置为,unsigned
则可以255
用作最大值。如果您没有明确设置该列,因为unsigned
这意味着它将接受负数(因此是一signed
列),在这种情况下,最大值现在将为127
.
The other answers are technically correct because by default Mysql will set all integer columns as signed
(able to use negative numbers). I just think this answer explains things a little more and is, perhaps, more germane to your original question.
其他答案在技术上是正确的,因为默认情况下,Mysql 会将所有整数列设置为signed
(能够使用负数)。我只是认为这个答案更能解释一些事情,并且可能与您最初的问题更密切相关。