Should I use BIT (1) or BOOL?

Mysql has two types that can contain logical data, bit and bool. Bit (1) seems more logical, since it should be 1 or 0, bool, according to the specifications, coincides with the linear (1)

+4
source share
4 answers

To store things semi-universal / portable for other database providers, use BIT. MySQL is one step ahead of most servers, even with the BOOLEAN keyword.

See: Comparing Different SQL Implementations

+4
source

Au contraire, bool looks much more logical, especially if you want to write down the truth and falsehood.

+3
source

I think it depends on your application and client library. Some layers of database abstraction may expect a boolean to be an integer. (I know technically a bit is an integer)

0
source

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

Does this mean that a bool can have more than two possible states (discarding the nullability value)? If so, then bit (1) is definitely better since there is no possibility for ambiguity. What would your application do when it received a value of 3 for the true / false field?

0
source

Source: https://habr.com/ru/post/1304650/


All Articles