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

WBOY
Release: 2023-08-22 10:29:02
forward
1623 people have browsed it

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

Both BOOL and BOOLEAN work like TINYINT(1). You can say that they are all synonyms for TINYINT(1).

BOOLEAN

This is an example of BOOLEAN. A query that creates a table with columns of type boolean.

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

The query to insert records into the table using the 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)
Copy after login

Use the select command to display all values in the table. The query is as follows −

mysql> select *from Demo;
Copy after login

Output

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

BOOL

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

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

Use the insert command to insert records in the table. 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)
Copy after login

Use the select command to display all values in the table. The query is as follows −

mysql> select *from Demo1;
Copy after login

Output

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

Look at the sample output, false is converted to 0. That means BOOL and BOOLEAN implicitly convert into tinyint(1).

The above is the detailed content of What is the difference between MySQL's BOOL and BOOLEAN column data types?. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!