BOOLEAN or TINYINT confusion(BOOLEAN 或 TINYINT 混淆)
问题描述
我正在为一个需要使用布尔日期类型来仅存储真或假两种状态的网站设计数据库.我正在使用 MySQL.
在使用 phpMyAdmin 设计数据库时,我发现我同时拥有 BOOLEAN 数据类型和 TINYINT 数据类型.
我浏览了不同的文章,有人说 TINYINT 与 BOOLEAN 相同,没有区别.有人说 BOOLEAN 在 MySQL 中被转换为 TINYINT.
I was designing a database for a site where I need to use a boolean datetype to store only 2 states, true or false. I am using MySQL.
While designing the database using phpMyAdmin, I found that I have both the BOOLEAN datatype and the TINYINT datatype.
I went through different articles, some said TINYINT is the same as BOOLEAN, no difference. Some say BOOLEAN is converted into TINYINT in MySQL.
我的问题是,如果它们都相同,为什么存在两个?应该只有其中一个.
MY question is, if they both are same why do there exist two? There should be only one of them.
这是我阅读的文章的参考:
http://www.careerride.com/MySQL-BOOL-TINYINT-BIT.aspx
http://dev.mysql.com/doc/refman/5.5/en/numeric-type-overview.html
Here is the reference to the articles I read:
http://www.careerride.com/MySQL-BOOL-TINYINT-BIT.aspx
http://dev.mysql.com/doc/refman/5.5/en/numeric-type-overview.html
推荐答案
MySQL 没有内部布尔数据类型.它使用最小的整数数据类型 - TINYINT.
MySQL does not have internal boolean data type. It uses the smallest integer data type - TINYINT.
BOOLEAN 和 BOOL 等同于 TINYINT(1),因为它们是同义词.
The BOOLEAN and BOOL are equivalents of TINYINT(1), because they are synonyms.
尝试创建这个表 -
CREATE TABLE table1 (
column1 BOOLEAN DEFAULT NULL
);
然后运行 SHOW CREATE TABLE,你会得到这个输出 -
Then run SHOW CREATE TABLE, you will get this output -
CREATE TABLE `table1` (
`column1` tinyint(1) DEFAULT NULL
)
这篇关于BOOLEAN 或 TINYINT 混淆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:BOOLEAN 或 TINYINT 混淆


- 如何将 SonarQube 6.7 从 MySQL 迁移到 postgresql 2022-01-01
- 更改自动增量起始编号? 2021-01-01
- 在SQL中,如何为每个组选择前2行 2021-01-01
- 使用 Oracle PL/SQL developer 生成测试数据 2021-01-01
- SQL 临时表问题 2022-01-01
- 如何使用 pip 安装 Python MySQLdb 模块? 2021-01-01
- 如何将 Byte[] 插入 SQL Server VARBINARY 列 2021-01-01
- 以一个值为轴心,但将一行上的数据按另一行分组? 2022-01-01
- 导入具有可变标题的 Excel 文件 2021-01-01
- 远程 mySQL 连接抛出“无法使用旧的不安全身份验证连接到 MySQL 4.1+"来自 XAMPP 的错误 2022-01-01