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.
Author |
Topic |
taniarto
Starting Member
27 Posts |
Posted - 2013-10-12 : 00:32:12
|
I Have 2 Tables :Table one is master and table 2 is stock as follow :Master :ID Desc unit002 Ball Pcs001 Book pcsStock ID Qty002 0001 0I want to make delete trigger, which is if the master where delete the stock will be deleted too. I try but still not working..please help..thanks |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-10-12 : 04:52:17
|
you mean deleting a record in Master causing delete of the corresponding records in Stock------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
taniarto
Starting Member
27 Posts |
Posted - 2013-10-14 : 05:28:17
|
Yes... |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-10-14 : 07:05:50
|
You can do this in two ways1 Making FOREIGN KEY in Stock table with ON DELETE CASCADE option on ID column2 Creating a trigger like belowCREATE TRIGGER Trg_TodayUpStockON MasterFOR DELETEASBEGIN DELETE sFROM Stock sWHERE EXISTS (SELECT 1FROM DELETEDWHERE ID = s.ID)END ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
|
|
|