MySQL的BOOLEAN和BOOL都等同于TINYINT(1)。每当你使用BOOLEAN和BOOL数据类型创建列时,MySQL会隐式地将BOOLEAN和BOOL转换为TINYINT(1)。BOOLEAN和BOOL是TINYINT(1)的等价词,因为它们是同义词。
使用BOOLEAN数据类型创建表。创建表的查询语句。
mysql> create table BooleanDemo
-> (
-> IsOn BOOLEAN
-> );
Query OK, 0 rows affected (0.58 sec)
现在检查上述表的内部结构。查询如下 −
mysql> show create table BooleanDemo;
输出
+-------------+----------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+-------------+----------------------------------------------------------------------------------------------------------------------------------+
| BooleanDemo | CREATE TABLE `booleandemo` ( `IsOn` tinyint(1) DEFAULT NULL) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci |
+-------------+----------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.01 sec)
看上面的示例输出,BOOLEAN被转换为tinyint(1)。BOOL数据类型也是如此。创建表的查询如下所示−
mysql> create table BOOLDemo
-> (
-> validUser BOOL
-> );
Query OK, 0 rows affected (0.61 sec)
现在检查表的内部结构。查询如下 -
mysql> show create table BOOLDemo;
输出
+----------+------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+----------+------------------------------------------------------------------------------------------------------------------------------------+
| BOOLDemo | CREATE TABLE `booldemo` (`validUser` tinyint(1) DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci |
+----------+------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)