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)。
廣告