Login ProductsSalesSupportDownloadsAbout |
Home » Technical Support » ElevateDB Technical Support » Support Forums » ElevateDB General » View Thread |
Messages 1 to 2 of 2 total |
Using triggers to cascade deletes |
Fri, Nov 15 2013 7:50 AM | Permanent Link |
Ian Turner | In the past I have implemented cascaded deletes from within Delphi but for my current project I would like to try using triggers (the first time I have ever used them, mmm). Tim wrote a post on this back in March 2010 -
<< Start a transaction on just the two tables in the BEFORE DELETE trigger: CREATE TRIGGER BeforeDeleteTrigger BEFORE DELETE ON Master BEGIN START TRANSACTION ON TABLES Master, Detail; END commit the transaction after the delete: CREATE TRIGGER AfterDeleteTrigger AFTER DELETE ON Master BEGIN EXECUTE IMMEDIATE 'DELETE FROM Detail WHERE MasterID='+OLDROW.ID; COMMIT; END be sure to roll it back if there's an error using an ERROR trigger: CREATE TRIGGER ErrorDeleteTrigger ERROR DELETE ON Master BEGIN ROLLBACK; END >> I am just a little confused by the use of the AfterDeleteTrigger. Normally in Delphi, I would put me detail delete routine in the Master Table BeforeDelete event. Will deleting the Master record first not cause a problem with any foreigh key constraint, or does this mean that fk constraints cannot be used in this instance? Thanks, Ian |
Wed, Nov 20 2013 2:58 PM | Permanent Link |
Tim Young [Elevate Software] Elevate Software, Inc. timyoung@elevatesoft.com | Ian,
<< I am just a little confused by the use of the AfterDeleteTrigger. Normally in Delphi, I would put me detail delete routine in the Master Table BeforeDelete event. Will deleting the Master record first not cause a problem with any foreigh key constraint, or does this mean that fk constraints cannot be used in this instance? >> Yeah, that's a mistake - move the DELETE statement for the detail into the Before Delete trigger, but keep the COMMIT in the After Delete trigger. Tim Young Elevate Software www.elevatesoft.com |
This web page was last updated on Monday, April 29, 2024 at 05:23 AM | Privacy PolicySite Map © 2024 Elevate Software, Inc. All Rights Reserved Questions or comments ? E-mail us at info@elevatesoft.com |