mysql - TINYINT(M) 中列长度的用途是什么?

标签 mysql types

<分区>

我研究了 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/

相关文章:

mysql - 加入查询 laravel 4.2 的 Where 子句

MySQL Spatial CONTAINS 显示错误结果

c++ - 在运行时设置 vector 类型

variables - Rust 中相同范围内的变量阴影?

php - 无法在 mysql 数据库中正确插入希腊字符

php - 使用 PHP session 验证用户名

php - 我可以在PHP中混合使用MySQL API吗?

java - 为什么我在编译时遇到类型不匹配的问题

image - 如何将 DynamicImage 转换为 ImageBuffer?

c - C (GCC) 中数据类型的定义