title: Implement C# migration code in SQL
body: <p>I am new to SQL and today I got assigned an important task - to create a migration script for data in a table. From my understanding, a migration script is copying data from table A and move it to other tables B and C and so on. This seems to be frequent when database designs change constantly and the team wants to preserve data.</p>
  
  <p>My task:
  I have a <code>JobOffer</code> table, with the CityId field. Now the team wants to delete that field, and to preserve information they will add the CityId to the <code>Address</code> table and connect both tables using an intermidiary table called <code>Location</code> (this allows a JobOffer to have several Addresses).</p>
  
  <p><img src="https://i.stack.imgur.com/iL8Xs.png" alt="enter image description here"></p>
  
  <p>I have no idea on how to perform this task. An analogy in c# of what I prentend is this:</p>
  
  <pre><code>foreach (var row in JobOffer)
  {
      int addressId;
      if (!Address.Contains(row.CityId)){
          addressId = Address.add(row.CityId);
          Locaion.add(row.JobOfferId, addressId);
      }
      else
      {
          Locaion.add(row.JobOfferId, Address.get(row.CityId));
      }
  }
  </code></pre>
  
  <p>How do I do it in SQL?</p>