<分区>
我研究了 MySQL 文档,现在不确定 TINYINT(M) 中的列长度规范 (M
) 是什么意思。 TINYINT UNSIGNED 的取值范围为 0 到 255,但 TINYINT(1) UNSIGNED
的取值范围为 0 到 9?
压缩效果更好吗?
<分区>
我研究了 MySQL 文档,现在不确定 TINYINT(M) 中的列长度规范 (M
) 是什么意思。 TINYINT UNSIGNED 的取值范围为 0 到 255,但 TINYINT(1) UNSIGNED
的取值范围为 0 到 9?
压缩效果更好吗?
最佳答案
来自关于 numeric type attributes: 的 MySQL 文档
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. For example, a column specified as SMALLINT(3) has the usual SMALLINT range of -32768 to 32767, and values outside the range permitted by three digits are displayed in full using more than three digits.
When used in conjunction with the optional (nonstandard) attribute ZEROFILL, the default padding of spaces is replaced with zeros. For example, for a column declared as INT(4) ZEROFILL, a value of 5 is retrieved as 0005.
也就是说,只有当您关心可以在左侧显示的 0 或者您处于 CLI 环境中时,才应考虑此属性。 此外,如果您将一个字段声明为 tinyint(2) 并且其中存储的数字是 113,则将显示所有 3 个字符(尽管之前的回答是这样说的)
关于mysql - TINYINT(M) 中列长度的用途是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20430661/