I was designing a database for a site where I need to use a boolean
datetype to store only 2 states, true
or false
. I am using MySQL
.
While designing the database using phpMyAdmin
, I found that I have both the BOOLEAN
datatype and the TINYINT
datatype. I went through different articles, some said TINYINT
is the same as BOOLEAN
, no difference. Some say BOOLEAN
is converted into TINYINT
in MySQL
.
MY question is, if they both are same why do there exist two? There should be only one of them.
Here is the reference to the article(s) I read:
MySQL does not have internal boolean data type. It uses the smallest integer data type - TINYINT.
The BOOLEAN and BOOL are equivalents of TINYINT(1), because they are synonyms.
Try to create this table -
CREATE TABLE table1 (
column1 BOOLEAN DEFAULT NULL
);
Then run SHOW CREATE TABLE, you will get this output -
CREATE TABLE `table1` (
`column1` tinyint(1) DEFAULT NULL
)