Bird
0
0

What will be the result of deleting a department that has employees assigned if the foreign key is defined with ON DELETE CASCADE?

medium📝 query result Q5 of 15
SQL - Database Design and Normalization
Consider a table employees(emp_id, name, department_id) where department_id is a foreign key. What will be the result of deleting a department that has employees assigned if the foreign key is defined with ON DELETE CASCADE?
AAll employees in that department will be deleted automatically
BThe delete will fail due to foreign key constraint
CThe department will be deleted but employees remain with invalid department_id
DThe department will be deleted and employees' department_id set to NULL
Step-by-Step Solution
Solution:
  1. Step 1: Understand ON DELETE CASCADE behavior

    This option deletes dependent rows automatically when referenced row is deleted.
  2. Step 2: Apply to employees and department

    Deleting a department cascades delete to employees with that department_id.
  3. Final Answer:

    All employees in that department will be deleted automatically -> Option A
  4. Quick Check:

    ON DELETE CASCADE deletes dependent rows [OK]
Quick Trick: ON DELETE CASCADE removes related rows automatically [OK]
Common Mistakes:
  • Assuming delete will fail with cascade
  • Thinking employees keep invalid foreign keys
  • Believing foreign keys set to NULL without ON DELETE SET NULL

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes