Constraints
Constraints enforce integrity independently of application code.
What it is
Constraints enforce integrity independently of application code.
When to use it
Protect against concurrent writes and alternate clients.
Syntax
NOT NULL | CHECK | UNIQUE | FOREIGN KEYExample
CREATE TABLE accounts (
id INTEGER PRIMARY KEY,
user_id INTEGER NOT NULL REFERENCES users(id),
currency TEXT NOT NULL CHECK (currency IN ('USD', 'EUR')),
balance_cents INTEGER NOT NULL DEFAULT 0 CHECK (balance_cents >= 0),
UNIQUE (user_id, currency)
);Common mistakes
CHECK behavior and type enforcement vary; SQLite default typing is permissive, consider STRICT tables where appropriate.