Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Appropriate data field type for true/false value?

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!

like image 865
Industrial Avatar asked Jun 07 '10 12:06

Industrial


People also ask

What is true and false in database?

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.

How get true or false value in SQL?

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".

What is data type for boolean in MySQL?

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.

How do I add a boolean value to a database?

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'.


1 Answers

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

like image 79
Bella Avatar answered Sep 27 '22 23:09

Bella