使用触发器标记
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。但其更新日期与教育表任何领域的任何更新相同。 :(
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
These both codes are giving me same result. I want only when these three fields
change one of them then School.RecID
update. But its update dating with any updates made in any field of Education Table. :(
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在更新触发时,您可以访问记录的新版本和旧版本。您已获得新版本“已插入”,只需将其与旧版本“已删除”进行比较即可。
In a trigger off an update you can access both the new and the old version of the record. You've got Inserted, the new version, you just need to compare it to Deleted, the old version.