How to Give a Column a Default Value in SQLite with DEFAULT
Some columns have an obvious starting value: a new task isn't done yet. DEFAULT gives a column that value, so an INSERT can leave the column out. This guide starts every task at 0, not done, with real output from SQLite 3.54.1.
Syntax
CREATE TABLE <table> (
<column> <type> DEFAULT <value>
);
| Part | What it means |
|---|---|
DEFAULT <value> | The value SQLite stores when an INSERT doesn't give one for this column |
<value> | A number, text in single quotes, NULL, or an expression in parentheses, such as (date('now')) |
SQLite's documentation on the DEFAULT clause: "The DEFAULT clause specifies a default value to use for the column if no value is explicitly provided by the user when doing an INSERT."
Prerequisites
- The sqlite3 command-line shell. This guide uses SQLite 3.54.1. Run
sqlite3 --versionto see yours; the SQLite download page has the command-line tools for Windows, macOS and Linux.
Step 1: Write the Script
Save this as default_value.sql:
CREATE TABLE tasks (
title TEXT NOT NULL,
done INTEGER NOT NULL DEFAULT 0
);
INSERT INTO tasks (title) VALUES ('Buy milk');
INSERT INTO tasks (title, done) VALUES ('Pay rent', 1);
SELECT * FROM tasks;

done INTEGER NOT NULL DEFAULT 0starts every task at 0, not done.- The first
INSERTlists onlytitle, sodonegets the default. - The second gives
donea value of its own, 1.
Step 2: Run It
In the folder that holds the script, run:
sqlite3 -table todo.db ".read default_value.sql"
sqlite3 opens the database file todo.db, and creates it when it isn't there. -table prints each result as a table, and .read runs the statements in the script. The command is the same in bash, zsh and PowerShell.
+----------+------+
| title | done |
+----------+------+
| Buy milk | 0 |
| Pay rent | 1 |
+----------+------+

Buy milk got 0 without its INSERT mentioning done. Pay rent gave its own value, 1, and kept it: a default only fills a column that the INSERT leaves out.
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
Giving the column NULL, as in VALUES ('Buy milk', NULL) | NOT NULL constraint failed: tasks.done. An explicit NULL is a value, so SQLite doesn't use the default | Leave the column out of the INSERT |
A function call without parentheses, DEFAULT date('now') | Parse error ...: near "(": syntax error | Wrap it in parentheses: DEFAULT (date('now')) |
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
NOT NULL constraint failed: tasks.done | The INSERT gave done the value NULL | Leave done out, or give it 0 or 1 |
Parse error near line 1 of default_value.sql: table tasks already exists | The script already ran on todo.db | Delete todo.db and run the script again |
FAQ
Can a default be today's date?
Yes, as an expression in parentheses: added_on TEXT DEFAULT (date('now')). A row inserted without added_on got today's date.
What's a column's default when it has no DEFAULT?
NULL. The documentation: "If there is no explicit DEFAULT clause attached to a column definition, then the default value of the column is NULL."
Conclusion
done INTEGER NOT NULL DEFAULT 0 gave Buy milk a 0 without the INSERT naming the column, and Pay rent kept the 1 it was given.
Additional Resources
- The DEFAULT clause — what a default value can be.
- CREATE TABLE — every column constraint.
