Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
I often have tables where I need to store a flag which can either be 1 or 0 (true or false, etc).
I've previously used TINYINT.
Should I instead use BIT(1)? Why or why not?
–
–
if you use a mysql version greater then 5.0.3
Bit
isn't anymore an alias for
Tinyint
but if you create a
bit
column it gets anyway
1 Byte
.
so use
Bit(1)
or
Tinyint(1)
is equal and you get no benefits if your table had only 1
Bit
column.
but if you had more true/false columns i suggest you to use
Bit
as each value of the bit columns are placed in the same
1 Byte
until it is filled.
if u use mysql lower then 5.0.3 then use
tinyint
or
bit
is totally fine. if you look at the mysql documentation on
bool
types you see that it is a alias for
tinyint
http://dev.mysql.com/doc/refman/5.0/en/numeric-type-overview.html
BOOL, BOOLEAN
These types are synonyms for TINYINT(1). A value of zero is considered
false. Nonzero values are considered true:
–
–
–
Thanks for contributing an answer to Stack Overflow!
-
Please be sure to
answer the question
. Provide details and share your research!
But
avoid
…
-
Asking for help, clarification, or responding to other answers.
-
Making statements based on opinion; back them up with references or personal experience.
To learn more, see our
tips on writing great answers
.