title: Make duplicates in varchar field not duplicate by adding an incrementing number
body: <p>I'm upgrading a DB schema. A table is divided into 2 tables. These two tables are linked and the only way to link them is using a varchar name field in the original table. </p>
  
  <p>Problem is that customer <em>could</em> have duplicate names, since name is not the Primary/Unique Key. </p>
  
  <p>I came here looking for ideas to make these names unique so it can be used as a key when moving the data to the two new linked tables. </p>
  
  <p>As I'm writing this, I had the idea of CONCATing the current PK to name (as in CONCAT(name,id) as newName) and use this as key. </p>
  
  <p>There's also a unique code field, but this only goes into one of the new tables. </p>
  
  <p>Example Schema: </p>
  
  <pre><code>tableA
  a_id INT(11) PRI AUTO_INCREMENT
  code VARCHAR(10) UNIQUE 
  name VARCHAR(30) NOT NULL
  
  newTableB
  b_id INT(11) PRI AUTO_INCREMENT
  name VARCHAR(30)
  
  newTableC
  c_id INT(11) PRI AUTO_INCREMENT
  b_id INT(11) FK-&gt;newTableB
  code VARCHAR(10) UNIQUE 
  </code></pre>
  
  <p>What I want: </p>
  
  <ol>
  <li>Generate New b_id's (auto_increment)  </li>
  <li>newTableB.name imported from tableA.name </li>
  <li>newTableC.code imported from tableA.code </li>
  <li>newTableC.c_id imported from tableA.a_id</li>
  </ol>
  
  <p>a_id is an FK in another fourth table that's staying the same. After the changes above, c_id will now be valid FK in this fourth table. </p>
  
  <p><strong>My Challenge:</strong> 
  How Do insert into these new tables but still keep the original name&lt;->code&lt;->a_id relationship and transfer tableA.a_id values to newTableC.c_id. Don't care if b_id gets new auto_incr. values. </p>
  
  <p>Not sure how clear I'm making problem come across, but feel free to ask any questions. </p>
  
  <p>Thanks
  Dan</p>