You'll need to do a few things to make this work well. First, you will have to know the structure so that you can delete all the related data prior to deleting the data in the principal table. That means also deleting data related to the related data. Second, you're not going to want to do all the deletes in a single transaction. This will lead to a huge transaction log and lots and lots of blocking. Instead, you should plan on breaking down the deletes into smaller chunks, say 1,000 rows at a time. To support this you'll need to load the data from your SELECT criteria as described into a temporary storage (temp table or table variable, since you'll be searching on it, probably a temp table is better). Then you can use this data to step through the delete process.
It's a lot of work, but it's the safest and most efficient mechanism I know.
Trending Articles
More Pages to Explore .....