Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Deleting from multiple tables

Author  Topic 

JimmyFo
Starting Member

11 Posts

Posted - 2007-06-15 : 15:59:30
Hi, I have a number of tables and I need to delete from all of them at once - I will be deleting one row in one table, then deleting all the rows in another which use that just deleted row as a foreign key; I ALSO need to delete from a third table, where any foreign keys that match any rows just deleted in the second table.

How can I do this? Do I need to do multiple selects, get the rows, then run stored procedures from there? Any other ways around this?

Thanks,
James

rmiao
Master Smack Fu Yak Hacker

7266 Posts

Posted - 2007-06-15 : 16:35:35
Did you use 'on delete cascade' when create fkey? If not, have to delete rows from fkey tables first.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-06-16 : 00:10:30
Do you want to delete all the tables in a Database?
Then tuncate them instead of deleting

http://sqlteam.com/forums/topic.asp?TOPIC_ID=65341

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -