0

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.

Ramin
  • 9
  • 3

1 Answers1

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