我正在尝试在employeepayhistory
表上创建一个触发器。每当我更新表格中的RATE
列时,都会显示其对月薪的影响,但如果我更新一条记录,它会给我整个记录的月薪。请帮忙。
CREATE TRIGGER MONTHTRG
ON HumanResources.EmployeePayHistory
FOR UPDATE
AS
BEGIN
DECLARE @Rate MONEY
SELECT @Rate=Rate FROM INSERTED
SELECT 'MONTHSAL'=Rate*PayFrequency*30 FROM HumanResources.EmployeePayHistory
END
答案 0 :(得分:0)
你还需要给出where条件,通常你会
DECLARE @Id bigint
SET @Id = (SELECT Id from Inserted)
SELECT 'MONTHSAL' = Rate * PayFrequency*30 From HumanResources.EmployeePayHistory where Humanresources.EmployeeID=@Id
如果主键被称为“Id”,那么这将是有效的,并且是唯一的。您也可以使用Unique键(应该是非NULL)
来执行此操作