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)
以上是BOOLEAN 或 TINYINT 在 MySQL 中存储值?的详细内容。更多信息请关注PHP中文网其他相关文章!