MySQL中tinyint(2)的最大值是多少?

时间:2022-11-08 16:57:40

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)tinyint(2)表示只显示...我是否正确?

4 个解决方案

#1


20  

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

#2


12  

MySQL 5.0 Reference Manual: Numeric Types

MySQL 5.0参考手册:数字类型

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 normal TINYINT(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(试试看)。

#3


5  

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

#4


0  

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.

这真的是无符号和签名的单词的含义,遗憾的是没有人向你解释这一点,所以我可以看出它为什么令人困惑。

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作为最大值。如果您没有明确地将列设置为无符号,则意味着它将接受负数(因此是有符号列),在这种情况下,最大值现在为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(能够使用负数)。我只是觉得这个答案可以解释一些事情,或许与你原来的问题更密切相关。

#1


20  

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

#2


12  

MySQL 5.0 Reference Manual: Numeric Types

MySQL 5.0参考手册:数字类型

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 normal TINYINT(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(试试看)。

#3


5  

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

#4


0  

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.

这真的是无符号和签名的单词的含义,遗憾的是没有人向你解释这一点,所以我可以看出它为什么令人困惑。

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作为最大值。如果您没有明确地将列设置为无符号,则意味着它将接受负数(因此是有符号列),在这种情况下,最大值现在为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(能够使用负数)。我只是觉得这个答案可以解释一些事情,或许与你原来的问题更密切相关。