What's the most appropriate (read least data consuming) data field to store a true/false/1/0 value in a mySQL database?
I have previously used a one character long tinyint, but I am not sure if it's the best solution?
Thanks!
A value of zero is considered false. Non-zero values are considered true. However, the values TRUE and FALSE are merely aliases for 1 and 0. See Boolean Literals, as well as the IS operator for testing values against a boolean.
There are no built-in values true and false . One alternative is to use strings 'true' and 'false' , but these are strings just like any other string. Often the bit type is used instead of Boolean as it can only have values 1 and 0 . Typically 1 is used for "true" and 0 for "false".
Boolean Data TypeMySQL does not have a boolean (or bool) data type. Instead, it converts boolean values into integer data types (TINYINT). When you create a table with a boolean data type, MySQL outputs data as 0, if false, and 1, if true.
You can insert a boolean value using the INSERT statement: INSERT INTO testbool (sometext, is_checked) VALUES ('a', TRUE); INSERT INTO testbool (sometext, is_checked) VALUES ('b', FALSE); When you select a boolean value, it is displayed as either 't' or 'f'.
tinyint(1)
Is basically aliased from the BOOL data type so it is fine.
See here
In addition, this has already been covered here:
Which MySQL data type to use for storing boolean values
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