Bird
0
0

You have this foreign key:

medium📝 Debug Q14 of 15
SQL - Table Constraints
You have this foreign key:
FOREIGN KEY (child_id) REFERENCES parent(id) ON UPDATE RESTRICT

What happens if you try to update a parent id that is referenced by a child row?
AThe child rows are deleted.
BThe update succeeds and child rows update automatically.
CThe child foreign keys are set to NULL.
DThe update is blocked and an error is raised.
Step-by-Step Solution
Solution:
  1. Step 1: Understand ON UPDATE RESTRICT behavior

    ON UPDATE RESTRICT prevents updating parent keys if child rows reference them.
  2. Step 2: Apply update attempt on referenced parent key

    Since child rows exist, update is blocked and error occurs.
  3. Final Answer:

    The update is blocked and an error is raised. -> Option D
  4. Quick Check:

    ON UPDATE RESTRICT blocks update if child exists [OK]
Quick Trick: RESTRICT blocks parent key update if child exists [OK]
Common Mistakes:
MISTAKES
  • Confusing RESTRICT with CASCADE
  • Expecting child keys to update automatically
  • Thinking child keys become NULL

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes