当其他 table 在不同的服务器上时,如何从 SQL table 更新它们
How to update SQL table from other table when they are on different servers
我已经运行以下命令来包含另一个服务器实例。
EXEC sp_addlinkedserver @server='Server'
现在我正在尝试使用此方法同步这些数据库:
UPDATE
[Server].[ServerDB].[dbo].[tableName]
SET
[Server].[ServerDB].[dbo].[tableName].[columnName] = [LocalDB].[dbo].[tableName].[columnName]
FROM
[Server].[ServerDB].[dbo].[tableName], [LocalDB].[dbo].[tableName]
WHERE
[Server].[ServerDB].[dbo].[tableName].id = [LocalDB].[dbo].[tableName].id
这给了我以下错误:
The objects "LocalDB.dbo.tableName" and "Server.ServerDB.dbo.tableName" in the FROM clause have the same exposed names. Use correlation names to distinguish them.
所以在摆弄它之后,我尝试了各种版本:
UPDATE
[Server].[ServerDB].[dbo].[tableName]
SET
[Server].[ServerDB].[dbo].[tableName].[columnName] = [LocalDB].[dbo].[tableName].[columnName]
FROM
[Server].[ServerDB].[dbo].[tableName] serverDB
INNER JOIN
[LocalDB].[dbo].[tableName] localDB
ON
serverDB.id = localDB.id
但他们都给我某种错误的再现:
The multi-part identifier "Server.ServerDB.dbo.tableName.allrows" could not be bound.
有人能看出我遗漏了什么吗?
使用联接更新时需要使用此语法:
UPDATE s
SET s.[columnName] = l.[columnName]
FROM
[Server].[ServerDB].[dbo].[tableName] s
INNER JOIN
[LocalDB].[dbo].[tableName] l
ON
l.id = s.id
UPDATE
serverDB
SET
[columnName] = localdb.[columnName]
FROM
[Server].[ServerDB].[dbo].[tableName] serverDB
INNER JOIN
[LocalDB].[dbo].[tableName] localDB
ON
serverDB.id = localDB.id
我已经运行以下命令来包含另一个服务器实例。
EXEC sp_addlinkedserver @server='Server'
现在我正在尝试使用此方法同步这些数据库:
UPDATE
[Server].[ServerDB].[dbo].[tableName]
SET
[Server].[ServerDB].[dbo].[tableName].[columnName] = [LocalDB].[dbo].[tableName].[columnName]
FROM
[Server].[ServerDB].[dbo].[tableName], [LocalDB].[dbo].[tableName]
WHERE
[Server].[ServerDB].[dbo].[tableName].id = [LocalDB].[dbo].[tableName].id
这给了我以下错误:
The objects "LocalDB.dbo.tableName" and "Server.ServerDB.dbo.tableName" in the FROM clause have the same exposed names. Use correlation names to distinguish them.
所以在摆弄它之后,我尝试了各种版本:
UPDATE
[Server].[ServerDB].[dbo].[tableName]
SET
[Server].[ServerDB].[dbo].[tableName].[columnName] = [LocalDB].[dbo].[tableName].[columnName]
FROM
[Server].[ServerDB].[dbo].[tableName] serverDB
INNER JOIN
[LocalDB].[dbo].[tableName] localDB
ON
serverDB.id = localDB.id
但他们都给我某种错误的再现:
The multi-part identifier "Server.ServerDB.dbo.tableName.allrows" could not be bound.
有人能看出我遗漏了什么吗?
使用联接更新时需要使用此语法:
UPDATE s
SET s.[columnName] = l.[columnName]
FROM
[Server].[ServerDB].[dbo].[tableName] s
INNER JOIN
[LocalDB].[dbo].[tableName] l
ON
l.id = s.id
UPDATE
serverDB
SET
[columnName] = localdb.[columnName]
FROM
[Server].[ServerDB].[dbo].[tableName] serverDB
INNER JOIN
[LocalDB].[dbo].[tableName] localDB
ON
serverDB.id = localDB.id