title: SQL Server : update a record foreign key references to another
body: <p>Due to data migration issue, there are duplicated records in Table A. </p>
  
  <p>Table A has two rows with same name "Jason", with id 1 and 3. I would like to move all the foreign key references from id = 3 in Link A &amp; Link B to 1, then delete the record of Jason with id = 3 from Table A. </p>
  
  <p><strong>Table A</strong></p>
  
  <pre><code>id     name       column2    column3
  -------------------------------------
   1     Jason        text      text
   2     Alice        text      text
   3     Jason        text      text   
  </code></pre>
  
  <p><strong>Link A</strong></p>
  
  <pre><code>id     column1     tableA_ID
  ----------------------------
   1        text        1     
   2        text        2      
   3        text        3  
  </code></pre>
  
  <p><strong>Link B</strong></p>
  
  <pre><code>id     column1     tableA_ID
  ----------------------------
   1        text        1     
   2        text        3      
   3        text        2  
  </code></pre>
  
  <p>For now, my simple solution would be</p>
  
  <pre><code>--update ids
  UPDATE db_A.`Link_A` SET id = 1 WHERE tableA_ID = 3;
  UPDATE db_A.`Link_B` SET id = 1 WHERE tableA_ID = 3;
  --delete ids
  DELETE db_A.`Table_A` WHERE id = 3;
  </code></pre>
  
  <p>The production server has tons of affected Ids, so I'm thinking if there is a better solution out there.</p>