constraint

FOREIGN KEY

Requires a matching parent for a non-NULL single-column reference. Add NOT NULL if the relationship is mandatory. SQLite enforcement must be enabled per connection. Target: PostgreSQL 17; focused syntax.

Formal Syntax & Structure

sql syntaxsql
FOREIGN KEY (parent_id) REFERENCES parent(id)

Working Example

Example Snippetsql
CREATE TABLE parent(id INT PRIMARY KEY NOT NULL); CREATE TABLE child(parent_id INT REFERENCES parent(id));INSERT INTO child VALUES (9);
SQL Reference