Microsoft SQL Server
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMicrosoft SQL Server

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old April 18th, 2006, 09:40 AM
rinkurathor1 rinkurathor1 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2006
Posts: 1 rinkurathor1 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 18 m 35 sec
Reputation Power: 0
Trigger for deleting row on the basis of key in another table

(i) i have more then two table with a common field ID. Now is there any way to write a trigger so that whenever a row is deleted fron one table,the all rows in all other tables having same ID should be deleted.


(ii) another requirement is to write a trigger so that all rows in the same table having same ID are deleted where any row is deleted.

Although i have solved these problems through code in vb.net but i wants to use Stored procedures or triggers.

Reply With Quote
  #2  
Old May 7th, 2006, 11:20 AM
som_dutt som_dutt is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2006
Posts: 12 som_dutt User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 56 m 5 sec
Reputation Power: 0
Hi Rinku!

You can create following trigger. I have some assumptions in my example.

Case [1] Other table have the same field ( Assumed as ID here). I assume Table2 and Table3 have the same ID column -
----------------------------------------------------------------------------------
Create trigger tr_001 on Table1
For Delete
as
delete from table2 where id in (Select id from deleted )
delete from table3 where id in (Select id form deleted )
go
----------------------------------------------------------------------------------

Case [2] Delete all rows when a row with same ID is deleted.

----------------------------------------------------------------------------------
CREATE trigger tr_002 on Table1
For delete
as
delete from Table1 where id in (select id from deleted )
go
----------------------------------------------------------------------------------
All the currently deleted values are stored in 'deleted' Table, that is used here. Inserted and Updated are also the tables that are used in various cases.

Reply soon ..

- Som Dutt

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMicrosoft SQL Server > Trigger for deleting row on the basis of key in another table


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway