How to update a SQL table from another table when they are on different servers
I have already run the following command to enable another server instance.
EXEC sp_addlinkedserver @server='Server'
Now I am trying to sync these databases using this:
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
This gave me the following error:
The "LocalDB.dbo.tableName" and "Server.ServerDB.dbo.tableName" objects in the FROM clause have the same public name. Use correlation names to differentiate between them.
So, after fiddling with it, I tried various versions of this:
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
But they all give me some idea of ββthe error:
The multipart identifier "Server.ServerDB.dbo.tableName.allrows" cannot be linked.
Can someone identify what I am missing?
+3
source to share