我经常有表格,我需要在其中存储可以为 1 或 0(真或假等)的标志。
我以前用过 TINYINT。
我应该改用 BIT(1) 吗?为什么或为什么不?
最佳答案
如果你使用的 mysql 版本大于 5.0.3 Bit
不再是 Tinyint
的别名但是如果你创建一个 bit
它无论如何都会得到 1 Byte
列。
所以使用 Bit(1)
或 Tinyint(1)
是相等的,如果您的表只有 1 个 Bit
列,您将没有任何好处.
但是如果你有更多的 true/false 列,我建议你使用 Bit
,因为位列的每个值都放在相同的 1 Byte
中,直到它被填满.
如果您使用低于 5.0.3 的 mysql,那么使用 tinyint
或 bit
完全没问题。如果您查看有关 bool
类型的 mysql 文档,您会发现它是 tinyint
http://dev.mysql.com/doc/refman/5.0/en/numeric-type-overview.html
BOOL, BOOLEAN
These types are synonyms for TINYINT(1). A value of zero is considered false. Nonzero values are considered true:
BIT is a synonym for TINYINT(1).
关于mysql - BIT(1) 或 TINYINT 用于 MySQL 中的标志,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25428842/