MySQL BOOL和BOOLEAN列数据类型之间有什么区别?

BOOL和BOOLEAN的行为都类似于TINYINT(1)。您可以说两者都是TINYINT(1)的同义词。

布兰

这是BOOLEAN的示例。用于创建具有列布尔类型的表的查询。

mysql> create table Demo
   -> (
   -> isVaidUser boolean
   -> );

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

mysql> insert into Demo values(true);

mysql> insert into Demo values(0);

使用选择命令显示表中的所有值。查询如下-

mysql> select *from Demo;

输出结果

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

布尔

这是BOOL的示例。以下是创建表的查询-

mysql> create table Demo1
   -> (
   -> isVaidUser bool
   -> );

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

mysql> insert into Demo1 values(1);

mysql> insert into Demo1 values(false);

使用选择命令显示表中的所有值。查询如下-

mysql> select *from Demo1;

输出结果

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

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