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 混淆
基础教程推荐
- 无法解决整理冲突 2021-01-01
- SQL 效率:WHERE IN 子查询 vs. JOIN 然后 GROUP 2021-01-01
- SSMS 中的权限问题:“对象 'extended_properties'、数据库 'mssqlsystem_resource'、... 错误 229)上的 SELECT 权限被拒绝" 2022-01-01
- 需要 MySQL 5.1 中的抽象触发器来更新审计日志 2021-01-01
- SQL Server 实例在登录协商期间返回无效或不受支持的协议版本 2021-01-01
- 将 SQL Server DateTime 列迁移到 DateTimeOffset 2021-01-01
- 是否可以执行按位分组功能? 2021-01-01
- 在 SQL 中连接多个表 2021-01-01
- 如何使用 mysql.connector 禁用查询缓存 2022-01-01
- SQL:使用来自具有相同列名的两个表中的数据... 2021-01-01
