Achieving Cascade Delete thru queires ?

  • Hai....,

             When specifying the relationship for my table, i haven't checked the option to perform cascaded delete operation. But during certain situation i want to make / perform cascaded delete operation while specifying the query. Is this possible or is there any workaround available for this.

     

  • There is no TSQL command to make the DELETE statement in your query perform a cascaded delete.  You would need to write 2 DELETE statements in your query.  The first DELETE statement to remove the child rows, the second DELETE should remove the parent rows. 

    On another note, you could also use an Instead of DELETE trigger on the parent table.  Write your logic into the trigger to delete the child rows first.

    John Rowan

    ======================================================
    ======================================================
    Forum Etiquette: How to post data/code on a forum to get the best help[/url] - by Jeff Moden

  • If you wish to cascade some of the time, based on the situation, then it sounds more like a business rule than a data integrity rule.  Business logic should be moved out of triggers and into the procedures that perform the deletes in those specific situations, or further up into the business layer, out of the database entirely.

    -Eddie

    Eddie Wuerch
    MCM: SQL

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply