UPDATE/JOIN(SQL Server)中另一台服务器上的表中的引用列

eek*_*142 3 sql-server naming join

我熟悉4部分命名,但每次尝试引用列时都会出错.例如:

UPDATE my_table
SET my_table.column1 = otherserver.otherdatabase.dbo.othertable.column1
FROM my_table INNER JOIN otherserver.otherdatabase.dbo.othertable
ON my_table.column2 = otherserver.otherdatabase.dbo.othertable.column2
Run Code Online (Sandbox Code Playgroud)

这会引发以下错误:

无法绑定多部分标识符"otherserver.otherdatabase.dbo.othertable.column1".

如果我只引用一个表,我从来没有遇到麻烦,但是当我追加列名时,它总是会抛出错误.有任何想法吗?SQL Server 2008

Mik*_*son 5

在限定列时,只需使用表名.

UPDATE my_table
SET my_table.column1 = othertable.column1
FROM my_table INNER JOIN otherserver.otherdatabase.dbo.othertable
ON my_table.column2 = othertable.column2
Run Code Online (Sandbox Code Playgroud)

或者使用别名.

UPDATE my_table
SET my_table.column1 = OT.column1
FROM my_table INNER JOIN otherserver.otherdatabase.dbo.othertable as OT
ON my_table.column2 = OT.column2
Run Code Online (Sandbox Code Playgroud)