Bird
0
0

You try to create a foreign key with ON DELETE SET NULL but get an error. What is a likely cause?

medium📝 Debug Q6 of 15
SQL - Table Constraints
You try to create a foreign key with ON DELETE SET NULL but get an error. What is a likely cause?
AThe foreign key references a non-existent table.
BThe parent table has no primary key.
CThe foreign key column is a primary key.
DThe foreign key column is NOT NULL.
Step-by-Step Solution
Solution:
  1. Step 1: Understand SET NULL requirement

    ON DELETE SET NULL requires the foreign key column to allow NULL values.
  2. Step 2: Identify cause of error

    If the foreign key column is NOT NULL, setting it to NULL on delete is invalid, causing an error.
  3. Final Answer:

    The foreign key column is NOT NULL, causing the error. -> Option D
  4. Quick Check:

    SET NULL needs nullable foreign key column [OK]
Quick Trick: Foreign key must allow NULL for SET NULL action [OK]
Common Mistakes:
MISTAKES
  • Ignoring NULL constraint on foreign key column
  • Assuming parent table keys cause this error
  • Confusing missing table with constraint error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes