Results 1 to 2 of 2
  1. #1
    Join Date
    Dec 2005
    Posts
    5

    Unanswered: Delete Multiple Records from Multiple Tables

    What is the simplist/correct way to delete multiple records from multiple tables. Any help appreciated. Thanks! (Yes, I'm totally new to this.)

    delete dbo.tblcase

    where dbo.tblcase.case_id in ('299760', '299757', '299739', '299732', '299902',
    '299901', '299897', '299894', '299873', '299872', '299870', '299865', '299860',
    '299858', '299854', '299846', '299838', '299834', '299821', '299813', '299803')


    delete dbo.tblcaseclient

    where dbo.tblcaseclient.case_id in ('299760', '299757', '299739', '299732', '299902',
    '299901', '299897', '299894', '299873', '299872', '299870', '299865', '299860',
    '299858', '299854', '299846', '299838', '299834', '299821', '299813', '299803')

    delete dbo.tblcaseinformation

    where dbo.tblcaseinformation.case_id in ('299760', '299757', '299739', '299732', '299902',
    '299901', '299897', '299894', '299873', '299872', '299870', '299865', '299860',
    '299858', '299854', '299846', '299838', '299834', '299821', '299813', '299803')

    delete dbo.tblcaselawyer

    where dbo.tblcaselawyer.case_id in ('299760', '299757', '299739', '299732', '299902',
    '299901', '299897', '299894', '299873', '299872', '299870', '299865', '299860',
    '299858', '299854', '299846', '299838', '299834', '299821', '299813', '299803')

    delete dbo.tblcaseprosecutor

    where dbo.tblcaseprosecutor.case_id in ('299760', '299757', '299739', '299732', '299902',
    '299901', '299897', '299894', '299873', '299872', '299870', '299865', '299860',
    '299858', '299854', '299846', '299838', '299834', '299821', '299813', '299803')

  2. #2
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    The simplest method is to establish relationships between your case table and the child tables, and define those relationships to have cascading deletes.
    Then just delete from your case table and let SQL Server handle the rest.
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

Posting Permissions

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