Merging two SQL tables with key conflicts
<p>I am trying to merge (union) two tables with the same structure. In a known block of rows, the primary key (an auto_increment integer) is in use in both tables for different data. Let's say it's the rows with primary keys 2000-2150. What is the best way to renumber these records in table B to unused values (say, in the range above 3000), so that the merge can proceed without conflicts? Should I just UPDATE them in place (say, by adding 1000 to each ID in that range), or are there better ways?</p>

<p>Notes:</p>

<ol>
<li><p>All references to this table are declared <code>ON UPDATE CASCADE</code>, so that I can safely renumber them without consequences.</p></li>
<li><p>The rest of the merge I can handle. Both tables contain useful data, and when a key outside that range is repeated, I will keep the version in Table A.</p></li>
</ol>