
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
BOOLEAN or TINYINT to store values in MySQL?
The MySQL BOOLEAN and BOOL both are equivalent to TINYINT(1). Whenever you create a column using BOOLEAN and BOOL data type, MySQL implicitly convert the BOOLEAN and BOOL to TINYINT(1). The BOOLEAN and BOOL are equivalents of TINYINT(1), since they are synonyms.
Create a table using BOOLEAN data type. The query to create a table.
mysql> create table BooleanDemo -> ( -> IsOn BOOLEAN -> ); Query OK, 0 rows affected (0.58 sec)
Now check internal structure of the above table. The query is as follows −
mysql> show create table BooleanDemo;
Output
+-------------+----------------------------------------------------------------------------------------------------------------------------------+ | 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)
Look at the above sample output, BOOLEAN is converted into tinyint(1). Same is case for BOOL data type also. The query to create a 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;
Output
+----------+------------------------------------------------------------------------------------------------------------------------------------+ | 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)
- Related Articles
- Does MySQL Boolean “tinyint(1)” holds values up to 127?
- What is difference between Boolean and tinyint(1) in MySQL?
- Converting boolean values to positive or negative sign in MySQL?
- What is the difference between TINYINT(1) and Boolean in MySQL?
- Should I use MySQL enum or tinyint for fields having values 1 and 0?
- MySQL TINYINT type to return 1 or IS NULL records
- Can we store CSS color values in MySQL?
- Change tinyint default value to 1 in MySQL?
- How to deal with 'Boolean' values in PHP & MySQL?
- How can we enter BOOLEAN values in MySQL statement?
- How can I update the boolean values in MySQL?
- Is it Possible to store and retrieve boolean values in a VARCHAR2 column in a table using JDBC?
- What is the difference between MySQL TINYINT(2) vs TINYINT(1)?
- Using Update statement with TINYINT in MySQL?
- What is the best data type to store money values in MySQL?

Advertisements