Foreign key
A column that points at another row, plus a rule stopping it from pointing at nothing. 'This order belongs to that customer.'
See it
What it is
A foreign key is one or more columns constrained to match a primary key or any unique key, plus the rule that refuses to let them point at a row that does not exist. 'orders.customer_id references customers.id' is the usual shape: the column carries the link, the constraint keeps it honest. The target does not have to be a primary key (any unique constraint works), does not have to be a single column (a composite key needs a matching composite reference), and does not even have to be another table (employees.manager_id pointing back at employees.id is a normal self-reference).
The interesting part is what happens on delete. ON DELETE RESTRICT blocks deleting a customer who still has orders, CASCADE deletes the orders with them, and SET NULL keeps the orders but forgets who placed them. Pick deliberately: CASCADE is convenient right up to the moment someone deletes one workspace row and takes 40,000 records with it.
Gotcha: Postgres indexes the referenced side automatically but not the referencing column. So 'orders.customer_id' is unindexed unless you say so, which makes both your joins and your cascading deletes crawl on a big table. Add the index yourself. Second gotcha: some teams skip foreign keys entirely for sharding or ORM reasons, which is a real tradeoff, but it means integrity is now your application's job and nobody will notice it slipping until the data is already wrong.
Ask AI for it
Add proper foreign key constraints to this schema: for every column that references another row, declare REFERENCES parent(key_columns) against that table's primary key or an existing unique key (including self-references and composite keys where that is the real shape), choose ON DELETE behavior explicitly (RESTRICT by default, CASCADE only for rows that are meaningless without the parent, SET NULL for optional links), and create an index on each referencing column. Show the ALTER TABLE statements plus a short table listing each relationship and why it got that delete rule.