Q47: What are Referential Actions on Foreign Keys (CASCADE, SET NULL, RESTRICT)?
Referential actions determine how child records react when a parent primary key row is updated or deleted:
- CASCADE: Automatically deletes or updates child records when the parent row is deleted or updated.
- SET NULL: Sets child foreign key values to
NULLwhen the referenced parent record is modified. - RESTRICT / NO ACTION: Prevents parent row modification or deletion if child rows still depend on it (throws a foreign key constraint violation error).
Key Takeaways
- CASCADE propagates parent key deletions directly to dependent child rows.
- RESTRICT / NO ACTION protects referential integrity by blocking parent deletions that have active child dependencies.