tags:

views:

100

answers:

4

Hi All,

What column type is best to use in a MySQL database for boolean values? I use boolean but my colleague uses tinyint(1).

+6  A: 

As far as i know, these datatypes are synonyms.

Māris Kiseļovs
Yep - http://dev.mysql.com/doc/refman/5.0/en/numeric-type-overview.html
Greg W
+1  A: 

boolean isn't a distinct datatype in MySQL; it's just a synonym for tinyint. See this page in the MySQL manual.

Personally I would suggest use tinyint as a preference, because boolean doesn't do what you think it does from the name, so it makes for potentially misleading code. But at a practical level, it really doesn't matter -- they both do the same thing, so you're not gaining or losing anything by using either.

Spudley
A: 

use enum its the easy and fastest

i will not recommend enum or tinyint(1) as bit(1) needs only 1 bit for storing boolean value while tinyint(1) needs 8 bits.

ref

http://stackoverflow.com/questions/3546186/tinyint-vs-enum0-1-for-boolean-values-in-mysql

JapanPro
We can't use enum as our database also needs to support sqlite
Skelton
your post tag is mysql, so i suggested.
JapanPro
+3  A: 

I am going to take a different approach here and suggest that it is just as important for your fellow developers to understand your code as it is for the compiler/database to. Using boolean may do the same thing as using tinyint, however it has the advantage of semantically conveying what your intention is, and that's worth something.

If you use a tinyint, it's not obvious that the only values you should see are 0 and 1. A boolean is ALWAYS true or false.

dj_segfault
That's exactly why I use boolean instead of tinyint.
Skelton