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)
 Delete the Multiple tables under single query

Author  Topic 

karthickraj.s
Starting Member

4 Posts

Posted - 2010-08-18 : 04:01:38
Hi All,
I have to delete the 3 tables under only one single query using sql server 2005.
I am not mentioned to the foreign key relation.

How can i delete all the 3 table content?..
I tried

Delete t1.*t2.*,t3.* from table t1 ,table t2,table t3 where t1.id = t2.Parent_id AND t2.id = t3.parent_id;

Its giving error [I bold]


Thanks & Regards
Karthick

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2010-08-18 : 04:04:39
you can't do that. One query can only affect one table. You have to do it in 3 separate query


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

karthickraj.s
Starting Member

4 Posts

Posted - 2010-08-18 : 04:17:42
quote:
Originally posted by khtan

you can't do that. One query can only affect one table. You have to do it in 3 separate query


KH
[spoiler]Time is always against us[/spoiler]





But i am searching it will be showing while setting CASCADE to the fields it will be deleted.

I dont know how to do that.Can you know please help me..

Thanks & Regards
Karthick
Go to Top of Page

jen
Master Smack Fu Yak Hacker

4110 Posts

Posted - 2010-08-18 : 04:26:39
you need to create a cascade delete trigger on the main table where all the FKs are referencing to

check cascading triggers in books online

--------------------
keeping it simple...
Go to Top of Page
   

- Advertisement -