Chapter 9 SQL Statements
479
WHEN clause The trigger fires only for rows where the search-condition
evaluates to true. The WHEN clause can be used only with row level
triggers.
♦
SQL/92 Persistent stored module feature. Some clauses are vendor
extensions.
♦
Sybase This syntax is different to that supported by Adaptive Server
Enterprise.
♦ When a new department head is appointed, update the manager_id
column for employees in that department.
CREATE TRIGGER tr_manager
BEFORE UPDATE OF dept_head_id
ON department
REFERENCING OLD AS old_dept NEW AS new_dept
FOR EACH ROW
BEGIN
UPDATE employee
SET employee.manager_id=new_dept.dept_head_id
WHERE employee.dept_id=old_dept.dept_id
END
Standards and
compatibility
Example