home
training courses
why choose us?
solutions
support
company
LearnItFirst User Forum
Welcome Guest
Search
|
New Posts
|
Members
|
Log In
|
Register
SQL Server Forum - LearnItFirst.com
»
Transact-SQL Programming
»
DML (SELECT, INSERT, UPDATE, DELETE) Questions
»
Best way to delete data from multiple tables who have foreign key relationship
Best way to delete data from multiple tables who have foreign key relationship
Options
Previous Topic
·
Next Topic
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
Back to top
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.
Back to top
Users browsing this topic
Guest
Forum Jump
SQL Server Database Administration
- General SQL Database Question & Answer
- Backup, Recovery and Disaster Recovery
- SQL Server Security
- Integration Services (SSIS) and DTS
Transact-SQL Programming
- DML (SELECT, INSERT, UPDATE, DELETE) Questions
- Stored Procedures, Triggers, & Functions
SQL Server Scripts, Code Samples and SSMS Custom Reports
- All SQL Server Versions
- SQL Server 2005/2008
- SQL Server Management Studio Custom Reports
Customer Service
- Video Requests
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.
SQL Server 2005 DBA Training Videos
SQL Server 2008 DBA Training Videos
Email this topic
RSS Feed
Watch this topic
Print this topic
Normal
Threaded