dbTalk Databases Forums  

Delete trigger pushing data to an archive table (tweak to implementation)

comp.databases.ibm-db2 comp.databases.ibm-db2


Discuss Delete trigger pushing data to an archive table (tweak to implementation) in the comp.databases.ibm-db2 forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Justin
 
Posts: n/a

Default Delete trigger pushing data to an archive table (tweak to implementation) - 08-16-2012 , 04:40 PM






The goal is to create a delete trigger that copies data to an archive table.. If data already exists for a rept_id, it should delete it first.

In this case, the test is delete from rept_css_asc where rept_id = -1 andthere are 2 records in rept_css_asc, but it fires each row and for each statement does not give provide variables. Fails on reference to o.rept_id. I prefer not to use the <B> bolded </B> area.

How do I prevent the trigger from deleting too much

CREATE TRIGGER "USERID"."REPT_CSS_ARCH_INS"
AFTER
DELETE
ON "USERID"."REPT_CSS_ASC"
REFERENCING OLD as "O"
FOR EACH ROW
MODE DB2SQL

begin atomic

delete from userid.rept_css_asc_archive where rept_id = o.REPT_ID
<B> and deleted_date < current timestamp </B>;

insert into userid.rept_css_asc_archive ( REPT_ID,css_id,DELETED_DATE )
values ( o.REPT_ID,o.css_id, current timestamp);

end~

Reply With Quote
  #2  
Old   
Justin
 
Posts: n/a

Default Re: Delete trigger pushing data to an archive table (tweak to implementation) - 08-17-2012 , 04:10 PM






Added a check for the deleted date... See below and it only deletes the previous records.

CREATE TRIGGER "USERID"."REPT_CSS_ARCH_INS"
AFTER
DELETE
ON "USERID"."REPT_CSS_ASC"
REFERENCING OLD as "O"
FOR EACH ROW
MODE DB2SQL

begin atomic

delete from userid.rept_css_asc_archive a where a.rept_id = o.REPT_ID and a.deleted_date < current timestamp ;

insert into userid.rept_css_asc_archive ( REPT_ID,css_id,DELETED_DATE )
values ( o.REPT_ID,o.css_id, current timestamp);

end~

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.