BEGIN
SET NOCOUNT ON;
IF (UPDATE( HighestDegreeDoc) OR UPDATE (GPA) OR UPDATE (CreditHours))
BEGIN
UPDATE [dbo].[School]
SET Uploaded = 1
FROM dbo.School
JOIN INSERTED i ON i.EmpID = dbo.School.RecID
END
RETURN
END
ALTER TRIGGER [dbo].[TrigEdu]
ON [dbo].[Education]
AFTER UPDATE
AS
BEGIN
SET NOCOUNT ON;
IF NOT (UPDATE( HighestDegreeDoc) OR UPDATE (GPA) OR UPDATE (CreditHours))
RETURN
UPDATE [dbo].[School]
SET Uploaded = 1
FROM dbo.School
JOIN INSERTED i ON i.EmpID = dbo.School.RecID
END
这两个代码都给了我相同的结果。我只希望这三个领域
更改其中一个,然后School.RecID
更新。但它的更新与任何教育表领域的任何更新约会。 :(
答案 0 :(得分:0)
在触发更新时,您可以访问新版本和旧版本的记录。您已经插入了新版本,只需要将它与旧版本的Deleted进行比较。
UPDATE dbo.School
SET Uploaded = 1
FROM dbo.School
JOIN INSERTED i ON i.EmpID = dbo.School.RecID
JOIN DELETED d ON d.EmpID = dbo.School.RecID
where i.HighestDegreeDoc != d.HighestDegreeDoc
or i.GPA != d.GPA
or i.CreditHours != d.CreditHours