SQLite foreign keys are off by default
Short answer
SQLite supports foreign key constraints, but enforcement is disabled by default.
PRAGMA foreign_keys = ON;
CREATE TABLE track (
id INTEGER PRIMARY KEY,
artist_id INTEGER REFERENCES artist(id) ON DELETE CASCADE
);
Key points
- Without the pragma, constraints are not enforced. [S1]
INTEGER PRIMARY KEYcolumns alias the rowid. [S2]
Claims
- id: C1 claim: Foreign key constraints are disabled by default in SQLite. source: S1 evidence: "SQLite (it is disabled by default)."
- id: C2 claim: Enable enforcement with PRAGMA foreign_keys = ON. source: S1 evidence: "sqlite> PRAGMA foreign_keys = ON;"
- id: C3 claim: CREATE TABLE creates a new table in an SQLite database. source: S2 evidence: "command is used to create a new table in an SQLite"
- id: C4 claim: The declared type of each column is part of CREATE TABLE. source: S2 evidence: "The declared type of each column in the table."
Sources
- [S1] SQLite Foreign Key Support. SQLite (sqlite.org). https://www.sqlite.org/foreignkeys.html . License: Public domain (sqlite.org). Accessed 2026-11-04.
- [S2] CREATE TABLE. SQLite (sqlite.org). https://www.sqlite.org/lang_createtable.html . License: Public domain (sqlite.org). Accessed 2026-11-04.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted).
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: SQLite (sqlite.org), SQLite Foreign Key Support, Public domain (sqlite.org); SQLite (sqlite.org), CREATE TABLE, Public domain (sqlite.org).
Cite this
iinventedlight. 2026. "SQLite foreign keys are off by default." iinventedlight Library, iil:note:405h0pf4, version of 2026-11-04. https://iinventedlight.com/library/notes/sqlite-foreign-keys/. License: CC-BY-4.0.
@misc{iil_note_405h0pf4,
author = {{iinventedlight}},
title = {{SQLite foreign keys are off by default}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-04},
url = {https://iinventedlight.com/library/notes/sqlite-foreign-keys/},
note = {Permanent ID iil:note:405h0pf4. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com.
For language models and agents: start at /llms.txt. This page in Markdown: /library/notes/sqlite-foreign-keys.md.