Full answer
Every nullable column adds work for every query that touches it: three-valued logic in filters, special handling in averages and joins, and more cases in application code. So the default should be NOT NULL, and NULL should be allowed on purpose.
Questions to ask for each column:
- Can a valid row exist without this value? An order cannot exist without an order date. A batch of students can exist before its end date is known.
- If the value is missing, what does that mean? If the answer is "not known yet", NULL fits. If it could mean either "unknown" or "not applicable", the column needs a clearer design.
- Is there a natural default? A
statuscolumn can default to 'planned'. A counter can default to 0. Then NOT NULL DEFAULT is better than NULL. - Is the value really optional data about a different thing? A user's optional company details may belong in a separate table that has a row only when the details exist.
A small table that follows these rules:
sql
CREATE TABLE batches (
id INTEGER PRIMARY KEY,
course TEXT NOT NULL,
start_date TEXT NOT NULL,
end_date TEXT, -- NULL means still running
status TEXT NOT NULL DEFAULT 'planned',
seats_taken INTEGER NOT NULL DEFAULT 0 CHECK (seats_taken >= 0),
CHECK (end_date IS NULL OR end_date >= start_date)
);
SELECT name, "notnull" AS not_null, dflt_value FROM pragma_table_info('batches') ORDER BY cid;| name | not_null | dflt_value |
|---|---|---|
| id | 0 | NULL |
| course | 1 | NULL |
| start_date | 1 | NULL |
| end_date | 0 | NULL |
| status | 1 | 'planned' |
| seats_taken | 1 | 0 |
Inserting a row with only the required fields shows the defaults and the deliberate NULL:
sql
INSERT INTO batches (course, start_date) VALUES ('SQL Basics', '2026-04-01');
SELECT id, course, start_date, end_date, status, seats_taken FROM batches;| id | course | start_date | end_date | status | seats_taken |
|---|---|---|---|---|---|
| 1 | SQL Basics | 2026-04-01 | NULL | planned | 0 |
end_date stays NULL on purpose and means "still running". status and seats_taken get real defaults rather than NULLs that every query would have to translate.
sql
CREATE TABLE batches (
id INTEGER PRIMARY KEY,
course TEXT NOT NULL,
start_date TEXT NOT NULL,
end_date TEXT, -- NULL means still running
status TEXT NOT NULL DEFAULT 'planned',
seats_taken INTEGER NOT NULL DEFAULT 0 CHECK (seats_taken >= 0),
CHECK (end_date IS NULL OR end_date >= start_date)
);
SELECT name, "notnull" AS not_null, dflt_value FROM pragma_table_info('batches') ORDER BY cid;
INSERT INTO batches (course, start_date) VALUES ('SQL Basics', '2026-04-01');
SELECT id, course, start_date, end_date, status, seats_taken FROM batches;Checked on SQLite 3.46.1, run twice with identical output.
Key points
- Default to NOT NULL; allow NULL deliberately
- NULL should have one clear meaning per column
- Prefer NOT NULL DEFAULT when a natural default exists
- Optional groups of attributes may belong in a separate table
Common mistakes
- Leaving every column nullable because the ORM does by default
- Using NULL to mean both 'unknown' and 'not applicable' in one column
Follow-ups
- How do you add NOT NULL to a column that already has NULLs?
- What is the cost of many nullable columns for queries?
Tips
- Walk through two or three columns of a concrete table instead of answering in the abstract