BOOLEAN Data Type
In this page:
Introduction to BOOLEAN
MySQL has no dedicated BOOLEAN storage type; declaring a column BOOLEAN is simply shorthand that MySQL silently converts to TINYINT(1) under the hood, storing TRUE as 1 and FALSE as 0.
Example: Introduction to BOOLEAN
CREATE TABLE users (is_active BOOLEAN);
INSERT INTO users VALUES (TRUE);
True and False Values
You can insert or compare using either the literal keywords TRUE/FALSE or the raw integers 1/0 — MySQL treats them as fully interchangeable, so there's no functional difference between the two styles.
Example: True and False Values
CREATE TABLE users (is_active BOOLEAN);
INSERT INTO users VALUES (TRUE);
INSERT INTO users VALUES (1);
Boolean in WHERE Clauses
Because the column is really just a small integer, you can reference it directly in a WHERE clause (e.g. WHERE is_active) without writing an explicit = TRUE comparison — MySQL treats any nonzero value as truthy.
Example: Boolean in WHERE Clauses
CREATE TABLE users (is_active BOOLEAN);
INSERT INTO users VALUES (TRUE), (FALSE);
SELECT * FROM users WHERE is_active;
Boolean Expressions
SUM() on a boolean-style column is a common trick for counting how many rows are true, since MySQL happily adds 1s and 0s together — a quick way to get a completion count without a separate COUNT(*) filter.
Example: Boolean Expressions
CREATE TABLE tasks (is_done BOOLEAN);
INSERT INTO tasks VALUES (TRUE), (TRUE), (FALSE);
SELECT SUM(is_done) AS completed_count FROM tasks;
Boolean Default Values
Giving a boolean column a DEFAULT value (commonly 0/false) ensures every new row starts in a known, predictable state rather than relying on the application to always remember to set it explicitly.
Example: Boolean Default Values
CREATE TABLE users (id INT, is_active BOOLEAN DEFAULT 0);
INSERT INTO users (id) VALUES (1);
Chapter Quiz — Complete all 8 topics to unlock
0/8 topics done
Complete these topics first: