Delete from 2 tables in one delete statement in SQL 2005

Hi,
i want to delete rows from two tables using one sql statement (inner join).

One table is tblEmployee and other is tblUser and i want to delete all record in both of table whose UserID is EE00001
0
saqib_dotnet
3/5/2009 2:23:02 AM
asp.net.sql-datasource 29906 articles. 0 followers. Follow

2 Replies
680 Views

Similar Articles

[PageSpeed] 32

Create a foreign key on the database table for that field, and set the cascade option to delete. When you delete from the main table, the corresponding entry from the dependent table will also be deleted.


Please Mark As Answer posts that helped you.

"If we learn from our mistakes, I should be brilliant by now."


MCTS - .NET Framework 2.0: Web Applications
0
nikki_doer_of_things
3/5/2009 3:30:58 AM

I agree with the previous poster. Otherwise you would have to have two separate delete statements which you need to wrap into transaction, so you would need to have an SP for that.


Beware of bugs in the above code; I have only proved it correct, not tried it.
(Donald Knuth)
0
Naom
3/5/2009 3:34:00 AM
Reply: