I am trying to update a table so that all values become identical to another table on a different database. I can do it with an insert command but not an update command.
This works:
INSERT [test1].[dbo].[table1]
SELECT * FROM [source].[dbo].[table1]
This does not:
UPDATE [test2].[dbo].[table1]
SET [source].[dbo].[table1] = [test2].[dbo].[table1]
nor this:
UPDATE [test2].[dbo].[table1]
SET
[test2].[dbo].[table1].[PKcolumn] = [source].[dbo].[table1].[PKcolumn]
,[test2].[dbo].[table1].[column2] = [source].[dbo].[table1].[column2]
,[test2].[dbo].[table1].[column3] = [source].[dbo].[table1].[column3]
WHERE
[source].[dbo].[table1].[PKcolumn] = [test2].[dbo].[table1].[PKcolumn]
The result is always some variation of this error message despite checking for errors countless times:
Msg 4104, Level 16, State 1, Line 1
The multi-part identifier “source.dbo.table1.PKColumn” could not be bound.
Any Suggestions?
Since
updatecan only affect one table, you don’t have to specify it:P.S. Depending on which database you’re using, you might want to check out the
MERGEstatement.