布尔或TINYINT混乱 [英] BOOLEAN or TINYINT confusion

查看:166
本文介绍了布尔或TINYINT混乱的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设计一个数据库,一个网站,我需要使用一个布尔datetype只存储2的状态,真的还是假的。我使用MySQL。结果
虽然使用phpMyAdmin设计数据库,我发现我都布尔数据类型和数据类型TINYINT。结果
我通过不同的文章了,有的说TINYINT是一样的布尔,没有什么区别。有人说,布尔转换为TINYINT在MySQL中。

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.

下面是引用我读了文章:结果
<一href=\"http://www.careerride.com/MySQL-BOOL-TINYINT-BIT.aspx\">http://www.careerride.com/MySQL-BOOL-TINYINT-BIT.aspx

<一href=\"http://dev.mysql.com/doc/refman/5.5/en/numeric-type-overview.html\">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.

布尔和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
)

这篇关于布尔或TINYINT混乱的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆