Bird
0
0

What will happen when you delete that customer?

hard📝 Application Q15 of 15
SQL - Table Constraints
You want to delete a customer from Customers table who has orders in Orders table. The Orders table has a FOREIGN KEY on CustomerID referencing Customers(CustomerID) with ON DELETE CASCADE. What will happen when you delete that customer?
AThe delete fails because orders exist for that customer
BThe customer is deleted and all their orders are automatically deleted
CThe customer is deleted but orders remain with invalid CustomerID
DThe delete succeeds but sets CustomerID in orders to NULL
Step-by-Step Solution
Solution:
  1. Step 1: Understand ON DELETE CASCADE effect

    ON DELETE CASCADE means deleting a parent row also deletes all related child rows automatically.
  2. Step 2: Apply to deleting a customer with orders

    Deleting the customer will also delete all orders linked by CustomerID in Orders table.
  3. Final Answer:

    The customer is deleted and all their orders are automatically deleted -> Option B
  4. Quick Check:

    ON DELETE CASCADE deletes related rows [OK]
Quick Trick: ON DELETE CASCADE removes child rows with parent [OK]
Common Mistakes:
MISTAKES
  • Assuming delete fails due to existing child rows
  • Thinking child rows remain with broken references
  • Confusing CASCADE with SET NULL behavior

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes