Computer >> Computer tutorials >  >> Programming >> MySQL

What is the difference between MySQL BOOL and BOOLEAN column data types?


BOOL and BOOLEAN both acts like TINYINT(1). You can say that both are synonyms for TINYINT(1).

BOOLEAN

Here is an example of BOOLEAN. The query to create a table with column boolean type.

mysql> create table Demo
   -> (
   -> isVaidUser boolean
   -> );
Query OK, 0 rows affected (1.08 sec)

The query to insert records in the table using insert command is as follows −

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)

Display all values from the table using select command. The query is as follows −

mysql> select *from Demo;

Output

+------------+
| isVaidUser |
+------------+
|          1 |
|          0 |
+------------+
2 rows in set (0.00 sec)

BOOL

Here is an example of BOOL. The following is the query to create a table −

mysql> create table Demo1
   -> (
   -> isVaidUser bool
   -> );
Query OK, 0 rows affected (0.54 sec)

Insert records in the table using insert command. The query is as follows −

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)

Display all values from the table using select command. The query is as follows −

mysql> select *from Demo1;

Output

+------------+
| 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).