Delete rows from two tables

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bharadwajrv
    New Member
    • May 2007
    • 26

    Delete rows from two tables

    Hi there:

    i have a <master> table and a <transaction> table... When a record is deleted from <master> table, i need to make sure that, the associated records in <transaction> table is deleted... Can i do it in a single sql statement or should it be a separate 'delete' statement...

    thanks for your help..
    cheers
    Venu
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by bharadwajrv
    Hi there:

    i have a <master> table and a <transaction> table... When a record is deleted from <master> table, i need to make sure that, the associated records in <transaction> table is deleted... Can i do it in a single sql statement or should it be a separate 'delete' statement...

    thanks for your help..
    cheers
    Venu
    Sounds like a job for a trigger on the master table to me.

    Comment

    • bharadwajrv
      New Member
      • May 2007
      • 26

      #3
      Originally posted by r035198x
      Sounds like a job for a trigger on the master table to me.
      i cant use trigger for this due to project constraints... is it possible to have a SQL script to do this...??

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Originally posted by bharadwajrv
        i cant use trigger for this due to project constraints... is it possible to have a SQL script to do this...??
        Yep you can. Just make them seperate statements running one after the other.

        Comment

        • FritzLeblanc
          New Member
          • Jul 2007
          • 12

          #5
          You could also use referential integrity specifying cascade delete.

          Comment

          • r035198x
            MVP
            • Sep 2006
            • 13225

            #6
            Originally posted by FritzLeblanc
            You could also use referential integrity specifying cascade delete.
            I would prefer this method. It's always best to make the DB take care of these things because the DB usually has a longer memory than ours.

            Comment

            Working...