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 数据库 Apache Camel 2021-01-01
- 如何在 SQL 中将 Float 转换为 Varchar 2021-01-01
- 表 './mysql/proc' 被标记为崩溃,应该修复 2022-01-01
- MySQL 中的类型:BigInt(20) 与 Int(20) 2021-01-01
- oracle区分大小写的原因? 2021-01-01
- 如何根据该 XML 中的值更新 SQL 中的 XML 2021-01-01
- 什么是 orradiag_<user>文件夹? 2022-01-01
- 在 MySQL 中:如何将表名作为存储过程和/或函数参数传递? 2021-01-01
- mysql选择动态行值作为列名,另一列作为值 2021-01-01
