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 delete trigger

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-23-11, 00:38
ai_zaviour ai_zaviour is offline
Registered User
 
Join Date: Sep 2011
Posts: 53
DB2 delete trigger

Hi all

I want to create a trigger for deletion

Plz refer attachments for Two tables..

When a record delete from Parent table Child record also should delete

But im getting a error because of the relationship..

This is the trigger

CREATE TRIGGER "DB2ADMIN"."TRIG_ON_DEMAND_INFO_HITS_DELETE"
AFTER DELETE
ON "DB2ADMIN"."ON_DEMAND_INFO"
REFERENCING
OLD AS "OLDROW"
FOR EACH ROW
DELETE
FROM ON_DEMAND_INFO_HITS
WHERE INFO_ID = OLDROW.INFO_ID;

Error is : delete from "DB2ADMIN"."ON_DEMAND_INFO" where "INFO_ID"=22
com.ibm.db2.jcc.am.po: A parent row cannot be deleted because the relationship "DB2ADMIN.ON_DEMAND_INFO_HITS.FK_ON_DEMAND_INFO_HI TS_INFO_ID" restricts the deletion.. SQLCODE=-532, SQLSTATE=23504, DRIVER=4.8.86

Is there anyway to avoid the relationship and delete the record
Attached Thumbnails
DB2 delete trigger-11111.jpg   DB2 delete trigger-22222.jpg  
Reply With Quote
  #2 (permalink)  
Old 09-23-11, 02:19
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,196
Did you try a before trigger? Also, you could just define the foreign key with ON DELETE CASCADE and then you don't need the trigger.
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
Reply With Quote
  #3 (permalink)  
Old 09-23-11, 02:25
ai_zaviour ai_zaviour is offline
Registered User
 
Join Date: Sep 2011
Posts: 53
Thanx..

I alter the Key for ON DELETE CASCADE option...

Thank You..
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