找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索本站精品资源

首页 教程频道 mysql教程 查看内容

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

作者:模板之家 2023-8-22 10:29 138人关注

BOOL和BOOLEAN都像TINYINT(1)一样工作。你可以说它们都是TINYINT(1)的同义词。BOOLEAN这是BOOLEAN的一个例子。创建一个具有boolean类型列的表的查询。mysqlcreatetableDemo-(-isVaidUserboolean-);QueryOK,0rowsaffe ...

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

BOOL和BOOLEAN都像TINYINT(1)一样工作。你可以说它们都是TINYINT(1)的同义词。

BOOLEAN

这是BOOLEAN的一个例子。创建一个具有boolean类型列的表的查询。

mysql> create table Demo
   -> (
   -> isVaidUser boolean
   -> );
Query OK, 0 rows affected (1.08 sec)
登录后复制

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

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)
登录后复制

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

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)
登录后复制
登录后复制

Look at the sample output, false is converted to 0. That means BOOL and BOOLEAN implicitly convert into tinyint(1).


路过

雷人

握手

鲜花

鸡蛋
原作者: 网络收集 来自: 网络收集

全部回复(0)