所有整数类型都可以有一个可选
(非标准)属性UNSIGNED.
无符号类型可用于许可
列中仅包含非负数
或当您需要较大的鞋面时
列的数字范围.为了
例如,如果INT列为UNSIGNED,
列范围的大小是
相同,但其端点从
-2147483648和2147483647最多为0和4294967295.
All integer types can have an optional
(nonstandard) attribute UNSIGNED.
Unsigned type can be used to permit
only nonnegative numbers in a column
or when you need a larger upper
numeric range for the column. For
example, if an INT column is UNSIGNED,
the size of the column's range is the
same but its endpoints shift from
-2147483648 and 2147483647 up to 0 and 4294967295.
何时使用?
问自己一个问题:该字段是否会包含负值?
如果答案是否定的,那么您需要一个UNSIGNED
数据类型.
Ask yourself this question: Will this field ever contain a negative value?
If the answer is no, then you want an UNSIGNED
data type.
一个常见的错误是使用从零开始的自动递增INT
主键,但是类型为SIGNED
,在这种情况下,您永远都不会碰任何负数,您会将可能的ID的范围减小到一半.
A common mistake is to use a primary key that is an auto-increment INT
starting at zero, yet the type is SIGNED
, in that case you’ll never touch any of the negative numbers and you are reducing the range of possible id's to half.
这篇关于MySQL中的“无符号"是什么意思,什么时候使用它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!