I have two SQL table (Tbl_FoodPrice , Tbl_RatioContents), Tbl_FoodPrice contains food prices, and Tbl_RatioContents of animal food composition based on the contribution of each substance. I would like to change the price of the material's share in the Tbl_RatioContents when the price of food is changed in Table 1.
Asked
Active
Viewed 47 times
0
-
4https://stackoverflow.com/help/how-to-ask – Crowcoder Apr 12 '19 at 20:18
-
2Probably you want to tag entity-framework and the version of that which is used also. – JosephDoggie Apr 12 '19 at 20:24
-
Why not use stored procedure to handle your logic in DB? – Tony Dong Apr 12 '19 at 20:46
1 Answers
0
The data update trigger is triggered by an UPDATE operation. The INSERTED table stores row values after an update. For example, a trigger that will be triggered when adding and updating data:
USE somedb;
GO
CREATE TRIGGER FoodPrice_INSERT_UPDATE
ON Tbl_FoodPrice
AFTER INSERT, UPDATE
AS
UPDATE Tbl_FoodPrice
SET Price = Price + Price * 10
WHERE Id = (SELECT Id FROM INSERTED)
You will find more examples: Insert Update trigger how to determine if insert or update

DimaS
- 37
- 5