HiveBrain v1.2.0
Get Started
← Back to all entries
principlesqlMajor

Bit vs. Boolean columns

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
bitcolumnsboolean

Problem

Given that bit fields are just binary representations of data and need to be queried in slightly "strange" way.

Does it actually provide any benefit using a bit field for a boolean value? From what I can see it seems to suggest that space is the only real benefit.

Solution

Personally, I would use the BOOLEAN for a boolean value. But keep in mind the caveat that in MySQL, BOOLEAN is just a synonym of TINYINT(1) [src].

This, of course, means you can have values other than 0 or 1 if you are not careful. To avoid this, you can use the aliases TRUE and FALSE when inserting and updating data, as those map to 1 and 0 respectively.

For the sake of being complete, prior to 5.0.3, BIT was also a synonym of TINYINT(1).

Context

StackExchange Database Administrators Q#15801, answer score: 20

Revisions (0)

No revisions yet.