I'd like to create an AFTER UPDATE trigger that, when fired, takes the affected rows and inserts them into two separate tables. That requires two insert statements. I could create two separate triggers, each inserting into the desired table. However, I'd much rather consolidate that into ONE trigger, since the data to be inserted is the same for both. However, I'm having trouble with the syntax. BTW, I'm using IBM Data Studio v2.2.1.0 for my IDE. Here is sample code:
CREATE TRIGGER tgTable1_AfterUpdate
AFTER UPDATE OF COMPANYNUMBER,
DIVISIONNUMBER,
JOBNUMBER
ON Table1
REFERENCING NEW AS newrow
FOR EACH ROW MODE DB2SQL
BEGIN ATOMIC
INSERT INTO log1(scono, sdvno, sjbno)
VALUES(newrow.COMPANYNUMBER,
newrow.DIVISIONNUMBER,
newrow.JOBNUMBER);
INSERT INTO log2(scono, sdvno, sjbno)
VALUES(newrow.COMPANYNUMBER,
newrow.DIVISIONNUMBER,
newrow.JOBNUMBER);
END;
When I run this, I get the following errors:
[SQL0104] Token <END-OF-STATEMENT> was not valid. Valid tokens: ;.
[SQL5001] Column qualifier or table NEWROW undefined.
[SQL0104] Token <END-OF-STATEMENT> was not valid. Valid tokens: DECLARE.
It looks like the IDE is treating the "CREATE TRIGGER.. BEGIN ATOMIC" as one statement, "INSERT INTO ... ); INSERT INTO... );" as a separate statement (thus the second error) and finally, "END;" as a third statement.
So, it appears that I cannot create a trigger with multiple statements. I'm not sure if this is something with my IDE or if indeed this is a limitation.
Any help would be appreciated.
-Thanks