LearnItFirst User Forum

SQL Server 2008 SSAS Training Videos
Welcome Guest Search | New Posts | Members | Log In | Register

Best way to delete data from multiple tables who have foreign key relationship Options
khatauli
Posted: Thursday, May 06, 2010 4:14:44 PM
Rank: Newbie

Joined: 5/6/2010
Posts: 1
Points: 3
Where do you live?: USA
Hi there, I have to delete some rows from a table based on timestamp, but this table has foreign key relationship with other table.

So before I can delete rows from this table, I need to delete related rows from other table.

But this other table also has foreign key relationship with third table, and third table with 4th table.

So basically I will need to delete the rows from 4th Table, before I can delete third table rows, and so on.

What is the best way to achieve this.

I started with first 4 joins to delete the rows in 4th table.

Than I did the join with 3 table to delete the 3rd table
and so on.

But in this approach, I am doing joins repeatetively. Is there a better way of handling the same thing.

Thanks
Scott Whigham
Posted: Thursday, May 06, 2010 4:31:29 PM


Rank: Super Mod

Joined: 3/20/2006
Posts: 476
Points: 1,053
Where do you live?: Dallas, TX
khatauli wrote:
... in this approach, I am doing joins repeatetively. Is there a better way of handling the same thing.
It sucks but, if this is a one-off job, I'd just suck it up and do it that way. If this is something you'll need to do repeatedly over an unknown set of tables, I'd look at codeplex.com for some tools to help you.
Users browsing this topic
Guest


Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.