加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MsSql教程 > 正文

使用INNER JOIN更新SQL Server中的多个表

发布时间:2020-12-12 08:30:43 所属栏目:MsSql教程 来源:网络整理
导读:参见英文答案 How to update two tables in one statement in SQL Server 2005?7个 我正在使用SQL Server,并尝试使用SQL一次更新多个表与一个查询: 以下查询: update table1set A.ORG_NAME = @ORG_NAME,B.REF_NAME = @REF_NAMEfrom table1 A,table2 Bwhere
参见英文答案 > How to update two tables in one statement in SQL Server 2005?7个
我正在使用SQL Server,并尝试使用SQL一次更新多个表与一个查询:

以下查询:

update table1
set A.ORG_NAME =  @ORG_NAME,B.REF_NAME = @REF_NAME
from table1 A,table2 B
where B.ORG_ID = A.ORG_ID
and A.ORG_ID = @ORG_ID

给出错误信息:

The multi-part identifier “A.ORG_NAME” could not be bound.

错误信息是什么意思?

解决方法

您不能在单个语句中更新该表,但是您得到的错误消息是由于别名,您可以尝试以下方式:
BEGIN TRANSACTION

update A
set A.ORG_NAME =  @ORG_NAME
from table1 A inner join table2 B
on B.ORG_ID = A.ORG_ID
and A.ORG_ID = @ORG_ID

update B
set B.REF_NAME = @REF_NAME
from table2 B inner join table1 A
    on B.ORG_ID = A.ORG_ID
    and A.ORG_ID = @ORG_ID

COMMIT

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读