SQL触发器在插入后更新另一个表列

时间:2013-03-21 01:01:07

标签: mysql sql triggers insert average

我有一个名为Ratings的表格,其中列User_NoRecipe_NoRating

插入后,我想更新另一个名为Avg_Rating的表上的Recipes列。

我是SQL语法的新手,但这基本上是我正在尝试做的事情

CREATE TRIGGER `Update_Avg` AFTER INSERT ON `Ratings`
FOR EACH ROW 
SELECT @recipeNo = Recipe_No FROM INSERTED;

SELECT @avg = AVG(Rating) FROM databs.Ratings WHERE
`Recipe_No` = @recipeNo;

INSERT INTO databs.Recipes (`Avg_Rating`) VALUES (@avg)
WHERE `Recipe_No` = @recipeNo; 

0 个答案:

没有答案