DB2 - Write trigger to record the inserted rows if the salary of employee exceeds 10000

Bandi
Posted by Bandi under Others category on | Points: 40 | Views : 805
CREATE TRIGGER INS_TRI_BEFORE
AFTER INSERT
ON EMPBKP
REFERENCING NEW AS N
FOR EACH ROW
BEGIN
IF (N.SALARY > 10000) THEN
INSERT INTO EMP_HISTORY (EMPLOYEE_ID, SALARY) VALUES (N.EMPLOYEE_ID, N.SALARY);
END IF;
END@

INSERT INTO EMPBKP (EMPLOYEE_ID, SALARY) VALUES (333, 50000)


CREATE TRIGGER TriggerName AFTER INSERT: it is same as SQL Server code

REFERENCING NEW AS N : here the NEW is the virtual table which stores recently inserted reocrd(s) during insert operation

FOR EACH ROW: DB2 has FOR EACH ROW option to refer the RECORD-based data

Comments or Responses

Login to post response