What does `unsigned` in MySQL mean and when to use it?(MySQL 中的 `unsigned` 是什么意思以及何时使用它?)
问题描述
无符号"在 MySQL 中是什么意思,我什么时候应该使用它?
What does "unsigned" mean in MySQL and when should I use it?
推荐答案
MySQL 说:
所有整数类型都可以有一个可选的(非标准)属性 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 中的 `unsigned` 是什么意思以及何时使用它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:MySQL 中的 `unsigned` 是什么意思以及何时使用它?
- 以一个值为轴心,但将一行上的数据按另一行分组? 2022-01-01
- 导入具有可变标题的 Excel 文件 2021-01-01
- 如何使用 pip 安装 Python MySQLdb 模块? 2021-01-01
- 在SQL中,如何为每个组选择前2行 2021-01-01
- 远程 mySQL 连接抛出“无法使用旧的不安全身份验证连接到 MySQL 4.1+"来自 XAMPP 的错误 2022-01-01
- SQL 临时表问题 2022-01-01
- 如何将 Byte[] 插入 SQL Server VARBINARY 列 2021-01-01
- 如何将 SonarQube 6.7 从 MySQL 迁移到 postgresql 2022-01-01
- 更改自动增量起始编号? 2021-01-01
- 使用 Oracle PL/SQL developer 生成测试数据 2021-01-01
