CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2006

    Deleting rows from multiple tables in SQL 2005

    Hi all,

    "Deleting rows from multiple tables in SQL 2005"

    I need to delete all the rows in the multiple rows where it's the same UserId. Please look at my Delete command below:


    DELETE FROM tableA
    tableB ON tableA.UserId = tableB.UserId INNER JOIN
    tableC ON tableA.UserId = tableC.UserId INNER JOIN
    tableD ON tableA.UserId = tableD.UserId
    WHERE (tableA.UserId = @UserId) AND (tableB.UserId = @UserId) AND (tableC.UserId = @UserId) AND (tableD.UserId = @UserId)


    What is happening from the above query is only the rows from tableA is getting deleted.

    Please help me on this.

    Thank you!
    Last edited by laxatcg1; January 5th, 2010 at 03:59 AM. Reason: Change in content
    Thank you for your support.

    Best regards,

  2. #2
    Join Date
    Jan 2006
    Fox Lake, IL

    Re: Deleting rows from multiple rows in SQL 2005

    If there are keys, you can set cascading delete to be true

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Jul 2000
    Milano, Italy

    Re: Deleting rows from multiple rows in SQL 2005

    or else you will have to write a Stored procedure that executes multiple deletions, deleting first from children tables and then from parents

    delete from tableChidlA where

    delete from tableChildB where

    delete from tableFather where

    but in this case to be sure you preserve integrity, you should also use transaction
    ...at present time, using mainly Net 4.0, Vs 2010

    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

Posting Permissions

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

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.