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
 General SQL Server Forums
 New to SQL Server Programming
 regarding trigger

Author  Topic 

ameya_amu
Starting Member

25 Posts

Posted - 2008-08-04 : 06:23:23
hello friend


i have three table

1) Artical_Demanded
2) Artical_Received
3) Artical_InStock


Artical_Demanded table contain the details of the artical demanded from manufacturer
which have following field
AID(pk),artical_id,quantity_demanded,dateofdemand,quantity_received


artical_received table contain details of the artical received from manufacture
which has following fields
artical_id,AID,quantity_received,dateofreceipt,rateperartical ( there can be multiple record for AID)


artical_inStock table contain detail of current avaliable stock of particular artical
artical_id,instock

if any record is inserted in artical_received table then quantity_received of artical_Demand table must be
incremented and instock field of artical_instock must be also incremented.can any one tell me how to use trigger
. when rows are updated in artical_received table(respective changes must be made in artical_demanded and artical_instock

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-08-04 : 10:55:16
[code]CREATE TRIGGER yourTrigger
ON Artical_Received
AFTER INSERT,UPDATE
AS
UPDATE ad
SET ad.quantity_received=ad.quantity_received+i.quantity_received
FROM inserted i
INNER JOIN Artical_Demanded ad
ON ad.AID=i.AID

UPDATE ad
SET ai.instock=ai.instock+i.quantity_received
FROM inserted i
INNER JOIN artical_inStock ai
ON ai.AID=i.AID
GO[/code]
Go to Top of Page
   

- Advertisement -