MySQL's BOOLEAN and BOOL are equivalent to TINYINT(1). Whenever you create a column using the BOOLEAN and BOOL data types, MySQL implicitly converts BOOLEAN and BOOL to TINYINT(1). BOOLEAN and BOOL are equivalents of TINYINT(1) because they are synonyms.
Create a table using the BOOLEAN data type. Query statement to create table.
mysql> create table BooleanDemo -> ( -> IsOn BOOLEAN -> ); Query OK, 0 rows affected (0.58 sec)
Now check the internal structure of the above table. The query is as follows −
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)
Looking at the above example output, BOOLEAN is converted to tinyint(1). The same is true for the BOOL data type. The query to create the table is as follows −
mysql> create table BOOLDemo -> ( -> validUser BOOL -> ); Query OK, 0 rows affected (0.61 sec)
Now check the internal structure of the table. The query is as follows -
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)
The above is the detailed content of BOOLEAN or TINYINT to store values in MySQL?. For more information, please follow other related articles on the PHP Chinese website!