Menu

1 / 4

Should a Boolean Column Be Nullable? NULL vs DEFAULT false vs a Status Column

DEV Community: mysql·Son Tran·5 days ago
#XOKIADLT
#devtomysql#devto#dev#null#marketing_opt_in
Long article (2011 words) — no AI summary yet.
Reading 0:00
15s threshold

Disclosure: I build Schemity , a desktop ERD tool - this post is from our blog and uses it for the examples.

TL;DR: Make a boolean NOT NULL with a default unless you can say in one sentence what NULL means. If you can, the third state deserves a name: a timestamp for when it happened, or a text column with a CHECK for a real tri-state. Converting an existing column means deciding what each NULL row meant first, because SET NOT NULL refuses the change while one remains.

A boolean column should be NOT NULL with a default in almost every schema, because a nullable boolean holds three states and every query and every line of application code has to guess what the third one means.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.