在一个表中使用触发器并更新另一表

发布于 2024-10-20 04:50:14 字数 437 浏览 4 评论 0原文

CREATE TRIGGER dbo.updateTrigger
   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 inerted i ON i.Uploaded = School.Uploaded
END
GO

这段代码有什么问题。我正在尝试更新学校表中的字段,以及教育表中更新(HighestDegreeDoc、GPA、CrediHours)时上传的字段。注意教育表有超过15个字段,(学校表中上传的字段仅当这3个字段更改时更新)

CREATE TRIGGER dbo.updateTrigger
   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 inerted i ON i.Uploaded = School.Uploaded
END
GO

What is Wrong with this code. i am trying to update field in School table , field uploaded when (HighestDegreeDoc , GPA, CrediHours) update in Education Table. NOTE Education Table has more than 15 field, (Uploaded Field in School table update only when these 3 field change)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

薄荷港 2024-10-27 04:50:14

只是一个猜测...

JOIN inerted i ON i.Uploaded = School.Uploaded

应该是...

JOIN inserted i ON i.SchoolId = School.SchoolId

看起来更新是您正在设置的某种标志。您可能想加入 ID 列。

Just a guess....

JOIN inerted i ON i.Uploaded = School.Uploaded

Should be...

JOIN inserted i ON i.SchoolId = School.SchoolId

Looks like Updated is some sort of flag that you are setting. You probably want to join on an ID column instead.

征﹌骨岁月お 2024-10-27 04:50:14

这只是一个拼写错误:它是 join insert ;)

而且我认为您的连接条件不好。

你能给我们 ddl 吗?

It's only a typo error : it's join inserted ;)

And I don't think your join condition is good.

Can you give us the ddl ?

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