Bird
0
0

A developer wrote this table creation:

medium📝 Debug Q7 of 15
SQL - Database Design and Normalization
A developer wrote this table creation:
CREATE TABLE orders (order_id INT PRIMARY KEY, customer_id INT NOT NULL, FOREIGN KEY (customer_id) REFERENCES customers(id) ON DELETE SET NULL);
But the database throws an error. What is the likely cause?
AON DELETE SET NULL is not supported in SQL
BPrimary key cannot be on order_id
CFOREIGN KEY syntax is incorrect
Dcustomer_id column is not nullable but ON DELETE SET NULL requires it
Step-by-Step Solution
Solution:
  1. Step 1: Understand ON DELETE SET NULL requirement

    This action sets foreign key column to NULL on delete, so column must allow NULL.
  2. Step 2: Check customer_id nullability

    If customer_id is NOT NULL, the action causes error because NULL cannot be assigned.
  3. Final Answer:

    customer_id column is not nullable but ON DELETE SET NULL requires it -> Option D
  4. Quick Check:

    ON DELETE SET NULL requires nullable foreign key column [OK]
Quick Trick: Nullable foreign keys needed for ON DELETE SET NULL [OK]
Common Mistakes:
  • Ignoring nullability of foreign key columns
  • Assuming ON DELETE SET NULL is invalid syntax
  • Confusing primary key rules

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes