
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is difference between Boolean and tinyint(1) in MySQL?
The basic difference between Boolean and tinyint(1) is only in the naming convention. If we say that we need true or false values then Boolean comes to our mind, instead of tinyint(1).
These data types are synonyms. It is up to us which data type we want to use- values can be 1 and 0 or true and false.
The following is an example.
Creating a table with Boolean data type.
mysql> create table BooleanDemo -> ( -> Light Boolean -> ); Query OK, 0 rows affected (0.52 sec)
Inserting records into table.
mysql> insert into BooleanDemo values(true); Query OK, 1 row affected (0.12 sec)
To display all record.
mysql> select *from BooleanDemo;
The following is the output that displays Boolean TRUE.
+-------+ | Light | +-------+ | 1 | +-------+ 1 row in set (0.00 sec)
Creating a table with tinyint(1) data type.
mysql> create table tinyint1Demo -> ( -> Light tinyint(1) -> ); Query OK, 0 rows affected (0.58 sec)
Inserting records into the table.
mysql> insert into tinyint1Demo values(1); Query OK, 1 row affected (0.12 sec)
To display all the records.
mysql> select *from tinyint1Demo;
Here is the output.
+-------+ | Light | +-------+ | 1 | +-------+ 1 row in set (0.00 sec)
Note − The only basic difference is in semantics. If we are talking about true or false then it is clear that data type should be boolean. But if we are talking about 0 or 1 then data type should be tinyint(1).
- Related Questions & Answers
- What is the difference between TINYINT(1) and Boolean in MySQL?
- What is the difference between MySQL TINYINT(2) vs TINYINT(1)?
- What is the difference between BIT and TINYINT in MySQL?
- Is there a difference in using INT(1) vs TINYINT(1) in MySQL?
- Does MySQL Boolean “tinyint(1)” holds values up to 127?
- What is the difference between MySQL BOOL and BOOLEAN column data types?
- BOOLEAN or TINYINT to store values in MySQL?
- What is difference between selenium 1 and Selenium 2
- Change tinyint default value to 1 in MySQL?
- Does MySQL converts bool to tinyint(1) internally?
- What is the difference between SQL and MySQL?
- MySQL TINYINT type to return <>1 or IS NULL records
- Difference between intvalue='1' and intvalue=1 in MySQL?
- What is the difference between MySQL NOW() and SYSDATE()?
- What is the difference between CHAR and NCHAR in MySQL?