MySQL 的 BOOL 与 BOOLEAN 列数据类型的区别是什么?


BOOL 和 BOOLEAN 都像 TINYINT(1)。你可以说两者都是 TINYINT(1) 的同义词。

BOOLEAN

下面是 BOOLEAN 的示例。创建具有布尔类型列的表的查询。

mysql> create table Demo
   -> (
   -> isVaidUser boolean
   -> );
Query OK, 0 rows affected (1.08 sec)

使用 insert 命令在表中插入记录的查询如下 −

mysql> insert into Demo values(true);
Query OK, 1 row affected (0.19 sec)

mysql> insert into Demo values(0);
Query OK, 1 row affected (0.17 sec)

使用 select 命令显示表中的所有值。查询如下 −

mysql> select *from Demo;

输出

+------------+
| isVaidUser |
+------------+
|          1 |
|          0 |
+------------+
2 rows in set (0.00 sec)

BOOL

下面是 BOOL 的示例。以下是创建表的查询 −

mysql> create table Demo1
   -> (
   -> isVaidUser bool
   -> );
Query OK, 0 rows affected (0.54 sec)

使用 insert 命令在表中插入记录。查询如下 −

mysql> insert into Demo1 values(1);
Query OK, 1 row affected (0.14 sec)

mysql> insert into Demo1 values(false);
Query OK, 1 row affected (0.16 sec)

使用 select 命令显示表中的所有值。查询如下 −

mysql> select *from Demo1;

输出

+------------+
| isVaidUser |
+------------+
|          1 |
|          0 |
+------------+
2 rows in set (0.00 sec)

查看示例输出,假转换为 0。这意味着 BOOL 和 BOOLEAN 隐式转换为 tinyint(1)。

更新于:30-7-2019

1000+ 浏览

开启你的职业生涯

通过完成课程获得认证

开始
广告
© . All rights reserved.