在一个表中使用触发器并更新另一表
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只是一个猜测...
JOIN inerted i ON i.Uploaded = School.Uploaded
应该是...
看起来更新是您正在设置的某种标志。您可能想加入 ID 列。
Just a guess....
JOIN inerted i ON i.Uploaded = School.Uploaded
Should be...
Looks like Updated is some sort of flag that you are setting. You probably want to join on an ID column instead.
这只是一个拼写错误:它是
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 ?