The following are Create Rule statement examples:
create rule emp_updates after delete, insert,
update of employee
execute procedure track_emp_updates
(name = new.name);
create rule emp_salary after update(salary, bonus)
of employee
where new.salary > old.salary
execute procedure check_sal
(name = old.name,
oldsal = old.salary,
newsal = new.salary,
oldbonus = old.bonus,
newbonus = new.bonus);
create procedure manager_emp_track
(ename varchar(30), mname varchar(30)) as
begin
update manager set employees = employees - 1
where name = :mname;
insert into mgrlog values
('Manager: ' + :mname +
'. Deleted employee: ' + :ename);
end;
create rule emp_delete after delete from employee
execute procedure manager_emp_track
(ename = old.name, mname = old.manager);
create procedure director_emp_track
(dname varchar(30)) as
begin
update director set employees = employees - 1
where name = :dname;
end;
create rule manager_emp_delete
after update(employees) of manager
where old.employees - 1 = new.employees
execute procedure director_emp_track
(dname = old.director);
create rule cust_zip_replace
before insert into customer
execute procedure verify_zip
(custno = c_no, zipcode = c_zip);