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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Delete from multiple table at once in sql server
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Constraint Violating Yak Guru

353 Posts

Posted - 09/09/2013 :  09:43:47  Show Profile  Reply with Quote
Can i Delete from multiple tables at once in sql server
I think something like this is available in mysql

Delete fe ,fd, fa,sf, sfsm
From dbo.FieldEnumeration As fe
Inner Join dbo.FieldDependency As fd
On fe.FieldEnumerationId = fd.FkFieldEnumerationId
Inner Join dbo.SimpleFieldDetail As sf
On fe.FkSimpleFieldDetailId = sf.SimpleFieldDetailId
Inner Join dbo.FieldAttributes As fa
On sf.SimpleFieldDetailId = fa.FkSimpleFieldDetailId
Inner Join dbo.SimpleFieldSectionMapper sfsm
On fd.ChildFieldId = sfsm.SimpleFieldSectionMappingId
And sf.SimpleFieldDetailId = sfsm.FkSimpleFieldDetailId
Inner Join dbo.SourceSection
On dbo.SimpleFieldSectionMapper.FkSourceSectionId = dbo.SourceSection.SourceSectionId
Inner Join dbo.TemplateSource
On dbo.SourceSection.FkTemplateSourceId = dbo.TemplateSource.TemplateSourceId
Inner Join dbo.Template tm
On dbo.TemplateSource.FkTemplateId = tm.TemplateId
Where tm.TemplateId = 1

Any idea how easily i can do this

Kamran Shahid
Principle Engineer Development

James K
Flowing Fount of Yak Knowledge

3873 Posts

Posted - 09/09/2013 :  10:26:26  Show Profile  Reply with Quote
T-SQL does not allow you to delete from multiple tables in one delete statement. If you want to preserve the atomicity of the deletions, the recommended way is to use a try-catch block and an explicit transaction.

You can use joins to pick up the rows that you want to delete, but the deletion has to be targeted at a single table.

T-SQL also supports cascade deletes - i.e., when you delete data from a table, you can set it up such that rows in other tables that are dependent on the row to be deleted via foreign key constraints will also get deleted.

Go to Top of Page

Constraint Violating Yak Guru

353 Posts

Posted - 09/10/2013 :  01:07:57  Show Profile  Reply with Quote
I know about the cascade delete but at the moment i needed the deletion with manual query. Could u help translating the above query into separate deletion queries.
I know i might needed the temprorary table to first select the ids into them then delete one by one

Kamran Shahid
Principle Engineer Development

Edited by - kamii47 on 09/10/2013 01:26:07
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.02 seconds. Powered By: Snitz Forums 2000