What is the concept of referential integrity and how is it enforced in database design?
Referential integrity ensures that relationships between tables are consistent. Specifically,
it ensures that a foreign key in one table must match a primary key or a unique key in
another table. This prevents invalid references from being made.
- Enforcing Referencing Integrity:
- Use foreign keys to create relationships between tables.
- Enforce actions like ON DELETE CASCADE, ON UPDATE CASCADE, or
ON DELETE RESTRICT to define how changes in parent tables affect related
child tables.
Example:
- A Foreign Key in the Orders table references the CustomerID in the Customers
table. If you try to delete a customer that has associated orders, referential integrity
will prevent the delete unless actions like CASCADE are specified.