mardi 4 août 2015

can't make a trigger update only the relevant rows

I'm working on a school project and my trigger gives me a hard time.

Its' purpose is to update the Rating field of an updated Product, but it updates all rows in Products instead.

CREATE TRIGGER Update_Rating 
ON  dbo.Reviews
FOR Insert
as
Update dbo.Products
set Rating=(Select [avarage_rating]=avg(r.Rating) 
            From dbo.Reviews as r join inserted  on r.ItemNumber = inserted.ItemNumber
            where r.ItemNumber = Inserted.ItemNumber)

Your help is much appreciated

Aucun commentaire:

Enregistrer un commentaire