I have a database table called A and now i have create a new table called B and create some columns of A in table B.
Eg: Suppose following columns in tables
Table A // The one already exists
Id, Country Age Firstname, Middlename, Lastname
Table B // The new table I create
Id Firstname Middlename Lastname
Now the table A will be look like,
Table A // new table A after the modification
Id, Country, Age, Name
In this case it will map with table B..
So my problem is now i need to kind of maintain the reports which were generated before the table modifications and my friend told me you need to have a data migration..so may i know what is data migration and how its work please.
Thank you.
Update
I forgot to address the reporting issue raised by the OP (Thanks Mark Bannister). Here is a stab at how to deal with reporting.
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):
The name related fields are no longer present in
tableApost data migration. We will have to perform a join withtableBto get the information. The query now changes to: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.
Original Answer
Consider the situation when you had only one table (
table A). A couple of rows in the table would look like this:After you add the second table (
table B) the name related fields are moved fromtable Atotable B.Table Awill have a foreign key pointing to thetable Bcorresponding to each row.This is the final picture. The catch is that the data will not move from
table Atotable Bon its own. Alas human intervention is required to accomplish this. If I were the said human I would follow the steps given below:table Bwith columnsId,Firstname,MiddlenameandLastname. You now have two tablesAandB.Ahas all the existing data,Bis empty .table A. This FK will be callednameand will reference theidfield oftable B.table Acreate a new row intable Busing theFirstname,MiddlenameandLastnamefields taken fromtable A.namefield oftable Awith theidof the newly created row intable B.The database now looks like this:
Firstname,MiddlenameandLastnamecolumns intable Aso you can drop them.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.