Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2011
    Posts
    85

    Unanswered: 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 Attached Thumbnails 11111.JPG   22222.JPG  

  2. #2
    Join Date
    May 2003
    Location
    USA
    Posts
    5,737
    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

  3. #3
    Join Date
    Sep 2011
    Posts
    85
    Thanx..

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

    Thank You..

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •