Close

2023-10-17

BOOLEAN Data Type For MySQL

BOOLEAN Data Type For MySQL

In MySQL, there isn’t a native BOOLEAN data type. However, BOOLEAN it is an alias for TINYINT(1). When you define a column of type BOOLEAN, MySQL internally creates it as a TINYINT(1) column.

In this context:

  • A value of 0 is considered FALSE
  • Non-zero values are considered TRUE

For example, the following two table definitions are equivalent:

CREATE TABLE example1 (
    is_active BOOLEAN
);
CREATE TABLE example2 (
    is_active TINYINT(1)
);

When you insert values into a BOOLEAN column, you can use TRUE and FALSE, which are equivalent to 1 and 0, respectively.

So, while MySQL doesn’t have a native BOOLEAN type, it provides functionality that effectively allows you to work with boolean values using the TINYINT(1) type.