MySQL
boolean column
default value
database design
SQL tutorial

Create boolean column in MySQL with false as default value?

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

In MySQL, creating a boolean column with a default of false is straightforward, but it helps to know what "boolean" means in MySQL. BOOLEAN and BOOL are aliases for TINYINT(1), so the database stores 0 and 1 even though the schema reads like a true-or-false field.

Basic Column Definition

The simplest definition is:

sql
1CREATE TABLE users (
2    id BIGINT PRIMARY KEY AUTO_INCREMENT,
3    is_active BOOLEAN NOT NULL DEFAULT FALSE
4);

This is readable and works as expected:

  • 'FALSE is stored as 0'
  • 'TRUE is stored as 1'
  • new rows get FALSE unless you provide another value

You can verify the behavior:

sql
1INSERT INTO users () VALUES ();
2INSERT INTO users (is_active) VALUES (TRUE), (FALSE), (1), (0);
3
4SELECT id, is_active FROM users;

The result is still numeric under the hood, but semantically it behaves like a boolean flag.

Altering an Existing Table

If the table already exists, add the column like this:

sql
ALTER TABLE users
ADD COLUMN is_active BOOLEAN NOT NULL DEFAULT FALSE;

That updates the schema and gives existing rows the default value where appropriate, subject to the engine and version behavior during the migration.

Why BOOLEAN Works Even Though MySQL Has No Native Boolean Type

MySQL accepts:

  • 'BOOLEAN'
  • 'BOOL'

but internally treats them as TINYINT(1). That means these definitions are effectively equivalent:

sql
1CREATE TABLE example_a (
2    enabled BOOLEAN NOT NULL DEFAULT FALSE
3);
4
5CREATE TABLE example_b (
6    enabled TINYINT(1) NOT NULL DEFAULT 0
7);

Most developers prefer BOOLEAN because the schema communicates intent better.

Querying and Updating Boolean Columns

Once the column exists, you can write readable statements:

sql
1UPDATE users
2SET is_active = TRUE
3WHERE id = 1;
4
5SELECT id
6FROM users
7WHERE is_active = FALSE;

Because the values are stored as 0 and 1, queries using numeric literals also work:

sql
SELECT id
FROM users
WHERE is_active = 0;

Still, TRUE and FALSE are usually clearer in application-facing SQL.

Enforcing Strict Boolean Semantics

Since the underlying type is numeric, MySQL can technically store values other than 0 and 1 unless you constrain the column. In modern MySQL versions, a check constraint can enforce that rule:

sql
1CREATE TABLE feature_flags (
2    id BIGINT PRIMARY KEY AUTO_INCREMENT,
3    enabled BOOLEAN NOT NULL DEFAULT FALSE,
4    CONSTRAINT chk_enabled_bool CHECK (enabled IN (0, 1))
5);

This is helpful if you want to protect against accidental writes such as 2 or -1.

Common Pitfalls

The most common mistake is assuming MySQL has a separate physical boolean type. It does not. BOOLEAN is an alias, so tools and drivers may still show the column as TINYINT.

Another mistake is leaving the column nullable when the business rule is really true-or-false. If NULL is allowed, you now have a third state: unknown. That may be useful, but it is not the same as a normal boolean flag.

A third issue is relying on truthy semantics without consistency in application code. If one part of the application writes 1 and another writes TRUE, that is fine. If something writes 2, your logic may behave unpredictably unless you enforce allowed values.

Finally, be careful with old data migrations. Adding NOT NULL DEFAULT FALSE to a large table may lock or rewrite data depending on the MySQL version, storage engine, and migration strategy. The SQL is simple, but the operational impact can still matter.

Summary

  • Use BOOLEAN NOT NULL DEFAULT FALSE for a readable MySQL boolean-style column.
  • MySQL stores boolean values as TINYINT(1) under the hood.
  • 'FALSE maps to 0, and TRUE maps to 1.'
  • Prefer NOT NULL unless you intentionally want a third unknown state.
  • Add a check constraint if you want to enforce only 0 and 1.

Course illustration
Course illustration

All Rights Reserved.