If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > DB2 Trigger Help

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-14-10, 13:40
abdul.haindade abdul.haindade is offline
Registered User
 
Join Date: Jul 2010
Posts: 2
DB2 Trigger Help

Hi there,
I am new to triggers and SP(never written an SP) but the 1st trigger on insert worked however the following does not work.

CREATE TRIGGER VNAUSER.DEL_LOCATION
AFTER INSERT OF LOCATION ON VNAUSER.PSHR1TEMP
REFERENCING OLD AS OLD_TAB
NEW AS NEW_TAB
FOR EACH ROW MODE DB2SQL
DELETE FROM VNAUSER.TBLLOCATION;
INSERT INTO VNAUSER.TBLLOCATION(Location) select distinct location from VNAUSER.PSHR1TEMP;

What I am trying to do with above Trigger is as soon as there in an insert in TBLPSHR1TEMP, the existing TBLLOCATION date should be deleted and a fresh data on Location should be added..However the risk that I realized is, if someone is accessing the TBLLocation.
However there is solution which I am finding it difficult to incorporate.

All I need to check is if there is a location in TBLPSHR1TEMP which is not there in TBLLOCATION and then its only an INSERT and NOT A DELETE of TBLLOCATION DATA

kindly provide guidance as to this
regards
aba
Reply With Quote
  #2 (permalink)  
Old 07-14-10, 13:44
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
Try the MERGE statement instead.

Andy
Reply With Quote
  #3 (permalink)  
Old 07-15-10, 12:43
abdul.haindade abdul.haindade is offline
Registered User
 
Join Date: Jul 2010
Posts: 2
Thanks

The MERGE seems to be a good option
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On