tags:

views:

115

answers:

5

Mysql has two types that can hold boolean data, bit and bool. Bit(1) seems more logical, because that has to be 1 or 0, bool is, according to the specs, the same as saying tinyint(1)

+1  A: 

Au contraire, bool seems much more logical, especially if you want to record truth and falsity.

High Performance Mark
A: 

I think it depends on your application and client library. Some database abstraction layers might expect that a boolean is a type of integer. (I know, technically a bit is an integer)

mikerobi
+3  A: 

For keeping things semi-universal / portable across other database vendors, use BIT. MySQL's a step ahead of most servers by even allowing the BOOLEAN keyword.

See: Comparison of different SQL implementations

tadamson
A: 

It's also possible to use the CHAR(0) type. A column that is defined as CHAR(0) NULL occupies only one bit and can take only the values NULL and '' (the empty string).

This is documented here: http://dev.mysql.com/doc/refman/5.1/en/string-type-overview.html

eugene y
A: 

bool is, according to the specs, the same as saying tinyint(1)

Does that mean that bool can have more than two possible states (setting aside nullability)? If so, then bit(1) is definitely better, as there's no possibility for ambiguity. What would your app do when it got a value of "3" for a true/false field?

Craig Walker
mysql interprets 0 as true, null as null, and non-0, non-null as false
Malfist