patternsqlModerate
What is the benefit of using BOOLEAN over TINYINT(1)?
Viewed 0 times
thetinyintbooleanwhatbenefitusingover
Problem
From MySQL manual, it says:
BOOL, BOOLEAN
These types are synonyms for TINYINT(1). A value of zero is considered
false. Nonzero values are considered true:
I created a BOOLEAN column with
If BOOLEAN works exactly the same as TINYINT(1), does it make any difference whether I use TINYINT(1) or BOOLEAN?
BOOL, BOOLEAN
These types are synonyms for TINYINT(1). A value of zero is considered
false. Nonzero values are considered true:
I created a BOOLEAN column with
0 as the default value. Then I update the value to 2. Logically, I would expect MySQL to accept either 0 or 1 since it is a boolean. However, MySQL did not issue an error or prevent me from performing the update.If BOOLEAN works exactly the same as TINYINT(1), does it make any difference whether I use TINYINT(1) or BOOLEAN?
Solution
Those two are really synonyms, so you can use them interchangeably. You won't see any difference between them.
If you want to allow 0 and 1 only, you can still use the
If you want to allow 0 and 1 only, you can still use the
bit type.Context
StackExchange Database Administrators Q#28422, answer score: 13
Revisions (0)
No revisions yet.