CREATE TRIGGER tri_emp_sal_check
NO cascade BEFORE
INSERT /*OR UPDATE*/ ON test.EMP
REFERENCING NEW AS newemp
FOR EACH ROW
MODE DB2SQL
SET newemp.SAL = CASE WHEN newemp.SAL <100 THEN 100
END
CREATE TRIGGER RecordHistory
AFTER
UPDATE OF rate ON test.CurrentRate
REFERENCING NEW AS newrate FOR EACH ROW
MODE DB2SQL
BEGIN ATOMIC INSERT INTO RateHistory VALUES (newrate.id, newrate.name, newrate.rate, current timestamp) ;
END
CREATE TRIGGER RateStatus
NO CASCADE BEFORE
UPDATE OF rate ON test.CurrentRate
REFERENCING OLD AS oldrate NEW AS newrate
FOR EACH ROW
MODE DB2SQL
SET newrate.status= CASE WHEN newrate.rate>=(select max(rate) from ratehistory where id=newrate.id) THEN 'Highest' WHEN newrate.rate<=(select min(rate) from ratehistory where id=newrate.id) THEN 'Lowest' WHEN newrate.rate>oldrate.rate THEN 'Rising' WHEN newrate.rate<oldrate.rate THEN 'Dropping' WHEN newrate.rate=oldrate.rate THEN 'Steady'
END