Which one is better, Tinyint with 0 and 1 values or ENUM 0,1 in MyISAM tables and MySQL 5.1?
In MySQL, TINYINT(1) and boolean are synonymous. Because of this, the MySQL driver implicitly converts the TINYINT(1) fields to boolean if the the Java tinyInt1isBit configuration property is set to true (which is the default) and the storage size is 1.
The basic difference between Boolean and tinyint(1) is only in the naming convention. If we say that we need true or false values then Boolean comes to our mind, instead of tinyint(1). These data types are synonyms. It is up to us which data type we want to use- values can be 1 and 0 or true and false.
There is no difference between TINYINT(1) and Boolean. The keyword Bool or Boolean internally converts into TINYINT(1) or we can say Bool or Boolean are synonymous with TINYINT(1).
MySQL a-z in Telugu Yes, MySQL internally convert bool to tinyint(1) because tinyint is the smallest integer data type. Look at the above sample output, the column isAgeGreaterThan18 data type is converted from bool to tinyint(1) internally.
You can use BIT(1)
as mentioned in mysql 5.1 reference. 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With