Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>Update</strong> </p> <p>I forgot to address the reporting issue raised by the OP (Thanks <a href="https://stackoverflow.com/users/359040/mark-bannister">Mark Bannister</a>). Here is a stab at how to deal with reporting.</p> <p>In the beginning (before data migration) a report to generate the name, country and age of users would use the following SQL (more or less):</p> <pre><code>-- This query orders users by their Lastname SELECT Lastname, Firstname, Age, Country FROM tableA order by Lastname; </code></pre> <p>The name related fields are no longer present in <code>tableA</code> post data migration. We will have to perform a join with <code>tableB</code> to get the information. The query now changes to:</p> <pre><code>SELECT b.Lastname, b.Firstname, a.Country, a.Age FROM tableA a, tableB b WHERE a.name = b.id ORDER BY b.Lastname; </code></pre> <p>I don't know how exactly you generate your report but this is the essence of the changes you will have to make to get your reports working again. </p> <p><strong>Original Answer</strong></p> <p>Consider the situation when you had only one table (<code>table A</code>). A couple of rows in the table would look like this:</p> <pre><code># Picture 1 # Table A ------------------------------------------------------ Id | Country | Age | Firstname | Middlename | Lastname 1 | US | 45 | John | Fuller | Doe 2 | UK | 32 | Jane | Margaret | Smith </code></pre> <p>After you add the second table (<code>table B</code>) the name related fields are moved from <code>table A</code> to <code>table B</code>. <code>Table A</code> will have a foreign key pointing to the <code>table B</code> corresponding to each row. </p> <pre><code># Picture 2 # Table A ------------------------------------------------------ Id | Country | Age | Name 1 | US | 45 | 10 2 | UK | 32 | 11 # Table B ------------------------------------------------------ Id | Firstname | Middlename | Lastname 10 | John | Fuller | Doe 11 | Jane | Margaret | Smit </code></pre> <p>This is the final picture. The catch is that the data will not move from <code>table A</code> to <code>table B</code> on its own. Alas human intervention is required to accomplish this. If I were the said human I would follow the steps given below:</p> <ol> <li>Create <code>table B</code> with columns <code>Id</code>, <code>Firstname</code>, <code>Middlename</code> and <code>Lastname</code>. You now have two tables <code>A</code> and <code>B</code>. <code>A</code> has all the existing data, <code>B</code> is empty .</li> <li>Add a foreign key to <code>table A</code>. This FK will be called <code>name</code> and will reference the <code>id</code> field of <code>table B</code>. </li> <li>For each row in <code>table A</code> create a new row in <code>table B</code> using the <code>Firstname</code>, <code>Middlename</code> and <code>Lastname</code> fields taken from <code>table A</code>.</li> <li>After copying each row, update the <code>name</code> field of <code>table A</code> with the <code>id</code> of the newly created row in <code>table B</code>. </li> </ol> <p>The database now looks like this:</p> <pre><code># Table A ------------------------------------------------------------- Id | Country | Age | Firstname | Middlename | Lastname | Name 1 | US | 45 | John | Fuller | Doe | 10 2 | UK | 32 | Jane | Margaret | Smith | 11 # Table B ------------------------------------------------------ Id | Firstname | Middlename | Lastname 10 | John | Fuller | Doe 11 | Jane | Margaret | Smith </code></pre> <ol start="5"> <li>Now you no longer need the <code>Firstname</code>, <code>Middlename</code> and <code>Lastname</code> columns in <code>table A</code> so you can drop them. </li> <li>voilà, you have performed a data migration!</li> </ol> <p>The process I just described above is but a specific example of a data migration. You can accomplish it in a number of ways using a number of languages/tools. The choice of mechanism will vary from case to case.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload