delete cascade

  • Hi, i'm new in this and i've been searching for a long time on google to find some good exemple.

    I need a stored procedure that can delete a record from parent table, but first to check if there are some records in child tables and if there're then delete first all records from child then delete record from parent table.

    Tnx for the help!

  • You should be using DRI ( Declarative referential integrity ) to do this.

    Try this link http://www.nerdymusings.com/LPMArticle.asp?ID=34



    Clear Sky SQL
    My Blog[/url]

  • Any exemple how to do this?

  • In the link above under "Cascading Actions"



    Clear Sky SQL
    My Blog[/url]

  • Hi,

    there is no need for stored procedure..

    You can do it by making foreign key with delete cascade

  • I don't like cascade delete foreign keys because they can affect hidden huge data operations. My suggestion is an own, custom delete procedure.

  • Both approaches (cascading deletes and custom procedures) have strengths and weaknesses.

    In a well-designed database, cascading triggers are often to be preferred since the server implements all the necessary checks and controls to ensure that the data remains consistent. It is all too easy to make subtle errors in custom procedures - most frequently concerning concurrency. Even quite experienced developers and DBAs struggle with this.

    In addition to Mr Ballantyne's link, make sure you read The Official Documentation thoroughly.

    If you tell us more about your requirements, we may be able to make further recommendations.

    Paul

Viewing 7 posts - 1 through 6 (of 6 total)

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