How to delete 20k records from a table having dependencies(foreign keys in other tables)

  • Delete From TableB

    where exists (select * from TableA

    where TableA.LinkedID=TableB.LinkedID )

    Repeat this for tables B and C, and then run

    Delete from TableA

    If you need to delete not all records from TableA you may use following code:

    Delete From TableB

    where exists (select * from TableA

    where {contition for the deletion} and TableA.LinkedID=TableB.LinkedID )

    _____________
    Code for TallyGenerator

  • If you want to do this all in one command, you need to turn cascading deletes on for foreign keys. That's what it's built for.


    - Craig Farrell

    Never stop learning, even if it hurts. Ego bruises are practically mandatory as you learn unless you've never risked enough to make a mistake.

    For better assistance in answering your questions[/url] | Forum Netiquette
    For index/tuning help, follow these directions.[/url] |Tally Tables[/url]

    Twitter: @AnyWayDBA

Viewing 2 posts - 1 through 3 (of 3 total)

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