Recall & Review
beginner
What does the ON DELETE CASCADE option do in a foreign key constraint?
It automatically deletes all rows in the child table that reference the deleted row in the parent table. This keeps data consistent by removing dependent records.
Click to reveal answer
beginner
Explain the ON DELETE SET NULL behavior in foreign keys.
When a referenced row in the parent table is deleted, the foreign key column in the child table is set to NULL. This means the child row no longer points to a parent row.
Click to reveal answer
intermediate
What happens if a foreign key has ON DELETE RESTRICT and you try to delete a parent row?
The deletion is blocked if there are any child rows referencing the parent. You must first remove or update child rows before deleting the parent.
Click to reveal answer
advanced
Describe the ON DELETE NO ACTION behavior.
It prevents deletion of a parent row if child rows exist, similar to RESTRICT. The difference is in timing: NO ACTION checks constraints at the end of the statement or transaction.
Click to reveal answer
beginner
What is the default behavior if ON DELETE is not specified in a foreign key?
The default is usually NO ACTION, meaning the database will prevent deleting a parent row if child rows exist referencing it.
Click to reveal answer
What does ON DELETE CASCADE do when a parent row is deleted?
✗ Incorrect
ON DELETE CASCADE deletes all child rows that reference the deleted parent row to keep data consistent.
Which ON DELETE option sets the foreign key in child rows to NULL when the parent is deleted?
✗ Incorrect
SET NULL sets the foreign key column in child rows to NULL when the referenced parent row is deleted.
If a foreign key uses ON DELETE RESTRICT, what happens when you try to delete a parent row with children?
✗ Incorrect
RESTRICT blocks deletion of the parent row if child rows exist referencing it.
What is the main difference between NO ACTION and RESTRICT in ON DELETE behavior?
✗ Incorrect
RESTRICT checks constraints immediately, while NO ACTION defers constraint checking until the end of the statement or transaction.
What is the default ON DELETE behavior if none is specified?
✗ Incorrect
The default ON DELETE behavior is usually NO ACTION, which prevents deletion if child rows exist.
Describe the different ON DELETE behaviors available for foreign keys and when you might use each.
Think about how deleting a parent row affects related child rows.
You got /5 concepts.
Explain why ON DELETE CASCADE can be useful and what risks it might have.
Consider a real-life example like deleting a customer and their orders.
You got /4 concepts.