Constraints & Referential Integrity
Use NOT NULL, UNIQUE, CHECK, and FOREIGN KEY constraints so the database enforces invariants — instead of relying on every code path to do so.
Constraints let the database itself enforce the rules your data must obey, rather than trusting every application code path to remember them. The difference matters because data usually outlives the code that created it and is touched by many programs, scripts, and migrations over its lifetime; an invariant enforced in one service's validation layer is one a batch job or an ad-hoc fix can quietly violate. A constraint in the schema is a guarantee that holds no matter what writes the data.
A passport office: every field on the form must be filled, every reference number must match a real entry. The clerk doesn't trust you to remember.