Bird
0
0

You have two tables:

hard📝 Application Q15 of 15
SQL - Table Relationships
You have two tables:
CREATE TABLE Departments (DeptID INT PRIMARY KEY, DeptName VARCHAR(50));
CREATE TABLE Employees (EmpID INT PRIMARY KEY, EmpName VARCHAR(50), DeptID INT, FOREIGN KEY (DeptID) REFERENCES Departments(DeptID) ON DELETE SET NULL);
If a department is deleted, what happens to employees linked to that department?
ATheir DeptID is set to NULL automatically
BThe delete is blocked and fails
CEmployees linked to that department are deleted
DNothing happens; DeptID remains unchanged
Step-by-Step Solution
Solution:
  1. Step 1: Understand ON DELETE SET NULL behavior

    This option means when the referenced row is deleted, the foreign key column in dependent rows is set to NULL.
  2. Step 2: Apply to Employees and Departments

    Deleting a department sets DeptID to NULL in Employees who referenced it, keeping employees but removing the link.
  3. Final Answer:

    Their DeptID is set to NULL automatically -> Option A
  4. Quick Check:

    ON DELETE SET NULL means foreign keys become NULL [OK]
Quick Trick: ON DELETE SET NULL clears foreign keys on delete [OK]
Common Mistakes:
MISTAKES
  • Assuming delete blocks or cascades employees
  • Thinking employees get deleted automatically
  • Ignoring ON DELETE action effects

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes