Results 1 to 2 of 2

Thread: Stored Proc

  1. #1
    Join Date
    Feb 2004
    Bangalore, India

    Question Unanswered: Stored Proc

    i have a table of the form

    table tab1(
    col1 bigint (ForeignKey col1 references mastertable1(col1))
    col2 bigint (ForeignKey col2 references mastertable2(col2))

    when i delete col2 from mastertable2, all the records in tab1 with
    the col2 value must be deleted.

    my problem is how to iterate through all the matching records in tab1 when i delete col2 from master table 2, using a SP


  2. #2
    Join Date
    Apr 2004
    Kansas City, MO
    You have this a little backwards. You can't delete the rows in mastertable "until after" you delete the rows in tab1.

    You need to identify the columns you are going to delete (maybe use a table variable), then:

    DELETE t1
    FROM tab1 t1
    INNER JOIN @temp t2 ON t1.col2 = t2.col2

    DELETE mt
    FROM mastertable2 mt
    INNER JOIN @temp t2 ON mt.col2 = t2.col2
    When life gives you a lemon, fire the DBA.

Posting Permissions

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