Hi Mirza,
Your first statement "...create a trigger immediately after the data was insert into a table...."....., are you creating the trigger after every insert, or is the trigger created and just firing after each insert? You should create the trigger once and it should just fire with each insert.
Your trigger does not contain compound statements so you don't need the keywords BEGIN/END.
I am by no means an expert on triggers, but I would rewrite the trigger as below:
--<ScriptOptions statementTerminator="@"/>
CREATE OR REPLACE TRIGGER DEV_SCHEMA.TEST_TABLE_INSERT
AFTER INSERT
ON DEV_SCHEMA.TEST_TABLE
FOR EACH STATEMENT
INSERT INTO DEV_SCHEMA.LOG (OPERATION_TYPE,TABLE_NAME,OPERATION_TIME, USERNAME)
VALUES('INSERT','DEV_SCHEMA.TEST_TABLE',CURRENT_TIMESTAMP,SESSION_USER)
@
Keep in mind, by using the 'FOR EACH STATEMENT' option I believe you're going to insert a row into DEV_SCHEMA.LOG whether your insert statement is successful or not.
Regards
------------------------------
Andy McLaughlin
Great American Insurance
Cincinnati
------------------------------
Original Message:
Sent: Tue September 10, 2024 05:23 AM
From: Mirza Tinjak
Subject: Creating Trigger AFTER INSERT (DB2 V11.5)
Hello everyone,the idea I'm trying to realize is to create a trigger immediately after the data was insert into a table. Trigger should log info about who inserted data and when. I will provide code below.
--<ScriptOptions statementTerminator="@"/>CREATE OR REPLACE TRIGGER DEV_SCHEMA.TEST_TABLE AFTER INSERT ON DEV_SCHEMA.TEST_TABLE FOR EACH STATEMENTMODE DB2SQLBEGIN ATOMICINSERT INTO DEV_SCHEMA.LOG(OPERATION_TYPE,TABLE_NAME,OPERATION_TIME, USERNAME) VALUES('INSERT','DEV_SCHEMA.TEST_TABLE',CURRENT_TIMESTAMP,SESSION_USER);END @
TEST_TABLE is row based organized table. Problem occurs when I want update records in TEST_TABLE using Data Stage. What happens is database lock.
------------------------------
Mirza Tinjak
------------------------------