What is a data type for storing logical values ​​in MySQL?

Possible duplicate:
What type of MySQL data to use to store boolean values?

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

I wanted to keep a boolean, MySQL has a BIT , but the .NET conversion of this data type is UINT64 .

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

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

Can anyone help and clarify my doubts?

+7
source share
3 answers

MySQL has BOOL and BOOLEAN, but they are synonyms for TINYINT (1). A value of zero is considered false. Nonzero values ​​are considered true. I think someone from MySQL thought about this and decided that TINYINT (1) is the best way to go. I have always used this myself.

There is another piece of information in this similar question: What is the difference between BIT and TINYINT in MySQL?

+6
source

BIT does not work the way you think, it is usually used to store bit fields and BIT(M) takes about (M+7)/8 (integer arithmetic) storage bytes. Using BIT(1) in any case takes a whole byte, the same as TINYINT , so don't worry about that.

If you're interested, the storage requirements for the various types are here .

+2
source

According to the MySQL manual, you can use bool and boolean, which are currently tinyint (1) aliases:

Reference: What type of MySQL data is used to store boolean values

Similar to MS SQL data type :

 0 = False 1 = True 
+1
source

All Articles