What is referential integrity?

Answer

Referential integrity ensures that relationships between tables remain consistent — a foreign key value in a child table must always match an existing primary key value in the parent table. It prevents orphan records (child rows with no matching parent). Enforced by the database via foreign key constraints. Violation examples: inserting an order for a non-existent customer, or deleting a customer who still has orders. Cascade options handle related row management: ON DELETE CASCADE, ON DELETE RESTRICT, ON DELETE SET NULL. Without referential integrity, data becomes inconsistent over time.