Subject trigger example in DataDef.pdf
Author ronaldorezende
I have a doubt about this trigger. I think that this example is
wrong. If the intend is prevent the application to store a value, the
trigger must be generated before the update occur. Or not? AFAIK, an
after update event is generated after the update transaction is
commited. I'm right? If not, when I must use the before udpate?


SET TERM !! ;
CREATE TRIGGER SAVE_SALARY_CHANGE FOR EMPLOYEE
AFTER UPDATE AS
DECLARE VARIABLE PCNT_RAISE;
BEGIN
PCNT_RAISE = (NEW.SALARY - OLD.SALARY) * 100 / OLD.SALARY;
IF (OLD.SALARY <> NEW.SALARY)
THEN
IF (PCNT_RAISE > 50)
THEN EXCEPTION RAISE_TOO_HIGH;
ELSE
BEGIN
INSERT INTO SALARY_HISTORY (EMP_NO, CHANGE_DATE,
UPDATER_ID, OLD_SALARY, PERCENT_CHANGE)
VALUES (OLD.EMP_NO, 'NOW', USER, OLD.SALARY,
PCNT_RAISE);
END
END !!
SET TERM ; !!