I am having problems with this logic...
I am trying to update a table with new data from another table, but only where the values from the new table are not in the old table.
And I get an error like:
Server: Msg 2627, Level 14, State 1, Line 1
Violation of PRIMARY KEY constraint 'PK_Table'. Cannot insert duplicate key in object 'Table'.
The statement has been terminated.
But I do not want duplicates! And I have the PK set on both tables Row1...so there should not be duplicate entries anyhow?
How do you do this correctly?
I am trying to update a table with new data from another table, but only where the values from the new table are not in the old table.
Code:
UPDATE Table SET Table.Row1 = AnotherTable.Row1, Table.Row2 = AnotherTable.Row2
FROM AnotherTable
Where Table.Row1 <> AnotherTable.Row1
And I get an error like:
Server: Msg 2627, Level 14, State 1, Line 1
Violation of PRIMARY KEY constraint 'PK_Table'. Cannot insert duplicate key in object 'Table'.
The statement has been terminated.
But I do not want duplicates! And I have the PK set on both tables Row1...so there should not be duplicate entries anyhow?
How do you do this correctly?