使用触发器标记

发布于 2024-10-20 02:34:00 字数 706 浏览 0 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

寄人书 2024-10-27 02:34:00

在更新触发时,您可以访问记录的新版本和旧版本。您已获得新版本“已插入”,只需将其与旧版本“已删除”进行比较即可。

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

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.

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文