What is the datatype to store boolean value in MySQL?

Deviprasad Das picture Deviprasad Das · May 13, 2011 · Viewed 12.4k times · Source

Possible Duplicate:
Which MySQL Datatype to use for storing boolean values?

I am a .NET programmer and using MySQL database for the first time in my life.

I wanted to store boolean value, MySQL has BIT, but the .NET conversion of this datatype is UINT64.

There is another datatype TINYINT(1), whose .NET equivalent is System.Boolean which will serve my purpose.

But why will I use TINYINT(1) (which can store value like 123, 22) instead of BIT, and it will take more space than BIT also (I guess)? It may be legal to use it but I dont think it is etical.

Can someone please help and clarify my doubt?

Answer

Kristoffer Lindvall picture Kristoffer Lindvall · May 13, 2011

MySQL have BOOL and BOOLEAN, but they are synonyms for TINYINT(1). A value of zero is considered false. Nonzero values are considered true. I guess someone at MySQL thought about it and decided TINYINT(1) is the preferred way to go. I've always used that myself.

There's some more info in this similar question: What is the difference between BIT and TINYINT in MySQL?