When should a SQLite column use DEFAULT rather than application-supplied values?
Quick answer
Use a SQLite column DEFAULT when you want the database to supply the same fallback whenever an INSERT omits that column. If a particular row needs a different value, supply it in the INSERT. A default does not replace an explicitly supplied NULL: an omitted column gets its declared default, or NULL if it has no default; an included column given NULL stays NULL. [S1][S2]
The question, the details, the next step.
A practical checklist
Decide whether omission should consistently mean one fallback.
Use a column DEFAULT when that fallback belongs in the schema.
Supply a value in the INSERT when it varies for a particular row.
Treat explicit NULL as distinct from leaving the column out.
Test omitted, NULL, and explicit-value inserts separately.
A few more useful answers
What happens if an omitted column has no DEFAULT?
Can an explicitly supplied NULL activate a column default?
What should I do when some inserts need the fallback and others need a special value?
Omit the column for rows that should use the declared fallback, and include it with the intended value for rows that need something different. [S2]
Sources
References used for this guide.
- [S1] SQLite CREATE TABLE: DEFAULT clause sqlite.org · Checked
- [S2] SQLite INSERT: values for omitted columns sqlite.org · Checked
