Bird
0
0

You have this foreign key constraint:

medium📝 Debug Q14 of 15
SQL - Table Relationships
You have this foreign key constraint:
FOREIGN KEY (ProductID) REFERENCES Products(ProductID) ON DELETE SET NULL

Which error will occur if you try to delete a product that is referenced by an order, but the ProductID column in Orders is defined as NOT NULL?
ADelete fails due to NOT NULL constraint violation
BDelete succeeds and sets ProductID to NULL
CDelete succeeds and removes the order row
DDelete succeeds without affecting Orders
Step-by-Step Solution
Solution:
  1. Step 1: Understand ON DELETE SET NULL behavior

    This option sets the foreign key column to NULL in referencing rows when the referenced row is deleted.
  2. Step 2: Check NOT NULL constraint conflict

    If the foreign key column is NOT NULL, setting it to NULL violates the column constraint, causing the delete to fail.
  3. Final Answer:

    Delete fails due to NOT NULL constraint violation -> Option A
  4. Quick Check:

    SET NULL + NOT NULL column = delete fails [OK]
Quick Trick: SET NULL fails if foreign key column is NOT NULL [OK]
Common Mistakes:
MISTAKES
  • Assuming delete succeeds and sets NULL anyway
  • Thinking delete removes referencing rows
  • Ignoring NOT NULL constraint on foreign key

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes