1
Vote

Missing "After Delete" Triggers!!!

description

There are two triggers In all "Detail Tables". It seems that in these tables we have missing "After Delete Triggers". It's obvious that if we delete one row in Detail Table we need to trigger Header Table to update the "SubTotal" Column.
For example in these tables:
[Purchasing].[PurchaseOrderHeader]
[Sales].[SalesOrderDetail]

Regards,
Saeid Hasani

comments

moatasem_ali wrote Sep 3, 2013 at 7:53 AM

try this

UPDATE HEAD_Table
SET net_wt =(Select Sum(DETAIL_Table.net_wt)
FROM DETAIL_Table INNER JOIN
                  HEAD_Table ON DETAIL_Table.Tbl_Hed = HEAD_Table.Tbl_ID)

                  Where HEAD_Table.Tbl_ID in (select Tbl_Hed from deleted)

SaeidHasani wrote Sep 3, 2013 at 9:19 AM

Dear ali,
I know the solution. But I commented here to correct for other people! This is a sample database for learning and here is the place for our feedback to other beginners have better sample.
By the way thanks for your time.