Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

question about delete triggers referencing old/new 1

Status
Not open for further replies.

ddiamond

Programmer
Apr 22, 2005
918
0
0
US
I found the following example of a delete trigger:
Code:
CREATE TRIGGER D_TRANSLOGGER
AFTER DELETE OF TRIGTEST/ATMTXN
REFERENCING OLD AS O_ROW NEW AS N_ROW
FOR EACH ROW MODE DB2SQL
INSERT INTO TRIGTEST/ATMTXNLOG
VALUES (
  'D', DATE(CURRENT TIMESTAMP), TIME(CURRENT TIMESTAMP),
  CHAR(N_ROW.ATMID)  || CHAR(N_ROW.ACCTID)|| CHAR(N_ROW.TCODE)||
  CHAR(N_ROW.AMOUNT) || CHAR(N_ROW.DESC),
  'DUMMY',
  CHAR(ATMID)||CHAR(ACCTID)|| CHAR(TCODE)||
  CHAR(AMOUNT)|| CHAR(DESC),
  'DUMMY' )
Why are they using N_ROW instead of O_ROW. I would expect O_ROW to contain the data before the delete, and N_ROW to contain the data after the delete which would be nil.

So I guess my real question is what do the old and new records refer to in a delete trigger.
 
This is the db2 message you should get when creating the trigger:

Code:
SQL0696N The definition of trigger "<trigger-name>" includes an
          invalid use of correlation name or transition table
          name "<name>".  Reason code="<reason-code>".

Explanation:

The trigger definition included an invalid use of "<name>".  The
value of "<reason-code>" indicates the specific problem as
follows.


 1 NEW correlation name and NEW_TABLE name are not allowed in a
DELETE trigger.

 2 OLD correlation name and OLD_TABLE name are not allowed in an
INSERT trigger.

 3 OLD_TABLE name and NEW_TABLE name are not allowed in a BEFORE
trigger.

 The statement cannot be processed.

User Response:

Remove the invalid correlation name or transition table name
along with the preceding keyword.

 sqlcode :  -696

 sqlstate :  42898

For db2 resoruces visit More DB2 questions answered at &
 
Thanks for your replies. So in a delete trigger, you should only reference old.

BTW - My platform as OS/400 v5r4.

 
Code:
 My platform as OS/400 v5r4.

Ooooo .. I haven't got a clue about this version. :)
My message was in DB2 LUW
Code:
So in a delete trigger, you should only reference old.

Logically, YES, unless DB2 iseries team have decided for some reason, OLD and NEW will have same values for INSERT and DELETE.
I would recommend to open a PMR and also check any of the recent APARs to see if this issue has been addressed. In any case, it is best to get the triggers correct now to avoid future "surprises"!!!

Sathyaram





For db2 resoruces visit More DB2 questions answered at &
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top