Bird
0
0

Which of the following is the correct syntax to add a foreign key with ON DELETE SET NULL in SQL?

easy📝 Syntax Q12 of 15
SQL - Table Constraints
Which of the following is the correct syntax to add a foreign key with ON DELETE SET NULL in SQL?
AFOREIGN KEY (child_id) REFERENCES parent(id) ON DELETE CASCADE
BFOREIGN KEY (child_id) REFERENCES parent(id) ON DELETE SET NULL
CFOREIGN KEY (child_id) REFERENCES parent(id) ON DELETE RESTRICT
DFOREIGN KEY (child_id) REFERENCES parent(id) ON DELETE NO ACTION
Step-by-Step Solution
Solution:
  1. Step 1: Identify the syntax for ON DELETE SET NULL

    The correct syntax includes the phrase ON DELETE SET NULL after the foreign key reference.
  2. Step 2: Match options with syntax

    FOREIGN KEY (child_id) REFERENCES parent(id) ON DELETE SET NULL exactly matches the required syntax for setting foreign keys to NULL on parent deletion.
  3. Final Answer:

    FOREIGN KEY (child_id) REFERENCES parent(id) ON DELETE SET NULL -> Option B
  4. Quick Check:

    ON DELETE SET NULL syntax = FOREIGN KEY (child_id) REFERENCES parent(id) ON DELETE SET NULL [OK]
Quick Trick: Look for 'ON DELETE SET NULL' phrase exactly [OK]
Common Mistakes:
MISTAKES
  • Choosing CASCADE instead of SET NULL
  • Confusing RESTRICT and NO ACTION
  • Missing ON DELETE clause

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes