Bird
0
0

Which of the following is the correct syntax to define a foreign key with ON DELETE CASCADE in a CREATE TABLE statement?

easy📝 Syntax Q3 of 15
SQL - Table Constraints
Which of the following is the correct syntax to define a foreign key with ON DELETE CASCADE in a CREATE TABLE statement?
AFOREIGN KEY (child_id) REFERENCES parent(id) ON CASCADE DELETE
BFOREIGN KEY (child_id) REFERENCES parent(id) DELETE CASCADE
CFOREIGN KEY (child_id) REFERENCES parent(id) ON DELETE CASCADE
DFOREIGN KEY (child_id) REFERENCES parent(id) ON DELETE CASCADE RESTRICT
Step-by-Step Solution
Solution:
  1. Step 1: Recall correct foreign key syntax

    The correct syntax includes ON DELETE CASCADE after the REFERENCES clause.
  2. Step 2: Check each option

    FOREIGN KEY (child_id) REFERENCES parent(id) ON DELETE CASCADE matches the correct syntax. Others have syntax errors or invalid keywords.
  3. Final Answer:

    FOREIGN KEY (child_id) REFERENCES parent(id) ON DELETE CASCADE -> Option C
  4. Quick Check:

    Correct syntax includes ON DELETE CASCADE [OK]
Quick Trick: Use ON DELETE CASCADE after REFERENCES [OK]
Common Mistakes:
MISTAKES
  • Omitting ON DELETE keyword
  • Swapping DELETE and CASCADE order
  • Adding extra keywords like RESTRICT

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes