问题描述
我正在为一个需要使用布尔日期类型来仅存储真或假两种状态的网站设计数据库.我正在使用 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 混淆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!