IntermediateBasic SELECT
Add a FOREIGN KEY constraint
The query
SQL
ALTER TABLE employees
ADD CONSTRAINT fk_dept
FOREIGN KEY (dept_id)
REFERENCES departments(dept_id)
ON DELETE SET NULL;Note
“Enforces referential integrity. ON DELETE SET NULL means if the department is deleted, the employee\'s dept_id becomes NULL instead of deleting the employee.