I have 2 tables (let's call them OriginalTable and NewValuesTable) with several columns. I am going to discuss only about the column in question.
Pallet ID - Primary key of OriginalTable
OriginalTable has around 35000 entries where the PalletID value is wrong. My NewValuesTable has the right PalletID values. Here is my issue:
- Let's take a sample set of the
OriginalTable
- These values are all wrong. These need to be replaced with new values from the
NewValuesTable. Like this:
- I don't know if the issue is obvious, but let me explain. The highlighted fields are the issue. When I update
21to22, there will be aPrimaryKey Constraintrelated error because it is a duplicate key. Likewise with34and68. How do I go around this issue?
This is what I thought: Maybe edit the values that have a Duplicate Key exception to something like W**. For instance, 22 in the NewValue table becomes W22, 34 becomes W34. Add a W or something like that. Then update the table with these values. Then update the OriginalTable's PalletID field to remove the W.
Does that seem like a smart way to go about this? Is there a better way to do this?


updateandjoin. They are ordered, yes. But thePalletIDfield does not have as simple a value as in the question. A typicalPalletIDlooks likeH2333431. TheNewValuestable has 35,000 rows because those are the ones that need changing. TheOriginalTablehas over 100,000 rows, but only the 35,000 rows with wrongPalletIDare in question.NewValuesTable, yes.OriginalTable, no.