更新 SQL Server 中的列触发器 - 错误多部分标识符无法绑定
我正在尝试找到正确的语法来创建简单的更新触发器。
我始终收到错误消息
无法绑定多部分标识符“AD.AgencyId”。
这是触发器,AgencyDivision 的 [FullName] 列也应包含其父级(代理机构)名称[机构].名称。
CREATE TRIGGER [dbo].[trUpdateAgencyDivisionFullName]
ON [dbo].[AgencyDivision] FOR UPDATE, INSERT
AS
BEGIN
UPDATE AD
SET AD.FullName = A.Name + ' , ' + AD.DivisionName
FROM AgencyDivision as AD, inserted AS i
JOIN Agency AS A
ON AD.AgencyId = A.Id
WHERE i.Id = AD.Id
END
我可以进行任何语法更改来解决这个问题吗?这个 JOIN 结构可以在触发器中工作吗?谢谢。
I am trying to find the correct syntax to create a simple update trigger.
I consistently get the error message
The multi-part identifier "AD.AgencyId" could not be bound.
Here is the trigger, The [FullName] column of AgencyDivision should contain it's parent's (Agency) Name as well [Agency].Name.
CREATE TRIGGER [dbo].[trUpdateAgencyDivisionFullName]
ON [dbo].[AgencyDivision] FOR UPDATE, INSERT
AS
BEGIN
UPDATE AD
SET AD.FullName = A.Name + ' , ' + AD.DivisionName
FROM AgencyDivision as AD, inserted AS i
JOIN Agency AS A
ON AD.AgencyId = A.Id
WHERE i.Id = AD.Id
END
Are there any syntax changes I can make to solve this? Can this JOIN structure work in triggers? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
听起来太明显了,但是您可以仔细检查 AgencyDivision 表上是否有 AgencyId 吗?
另外,仅从纯粹的语法角度来看,我会将其更改为:
在您的版本中,您正在混合 ANSI 和 theta 语法进行连接。
It sounds too obvious, but can you double check that the AgencyDivision table has an AgencyId on it?
Also, just from a pure syntax perspective, I would change it to:
In your version, you are mixing ANSI and theta syntax for your joins.