Bird
0
0

You have a parent table and two child tables referencing it. Child table A uses ON DELETE CASCADE, child table B uses ON DELETE SET NULL. If a parent row is deleted, what happens?

hard📝 Application Q8 of 15
SQL - Table Constraints
You have a parent table and two child tables referencing it. Child table A uses ON DELETE CASCADE, child table B uses ON DELETE SET NULL. If a parent row is deleted, what happens?
ABoth child tables delete their rows.
BChild table A rows are deleted; child table B rows have foreign keys set to NULL.
CBoth child tables set foreign keys to NULL.
DParent delete is blocked if any child rows exist.
Step-by-Step Solution
Solution:
  1. Step 1: Understand each ON DELETE action

    CASCADE deletes child rows; SET NULL sets foreign keys to NULL.
  2. Step 2: Apply to each child table

    Child table A rows referencing the parent are deleted; child table B rows have foreign keys set to NULL.
  3. Final Answer:

    Child table A rows deleted; child table B foreign keys set to NULL. -> Option B
  4. Quick Check:

    CASCADE deletes, SET NULL clears foreign keys [OK]
Quick Trick: CASCADE deletes; SET NULL clears foreign keys [OK]
Common Mistakes:
MISTAKES
  • Assuming both child tables behave the same
  • Thinking parent delete is blocked
  • Confusing SET NULL with delete

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes