Database - Merge tables with different structures

Asked

Viewed 155 times

0

My main question is: what is the best way to do and not which commands to use. What I need, basically, is the following:

I have two tables with different structures, in different databases. For example:

Database 1 - Client table structure: id - name - Cpf - phone - salary

Database 2 - Person table structure: id_pessoa - name - email - phone - city - Cpf - profession

What I need is to be able to insert the data from the first table (client) in the second table (person). Where, for example, client.id would be associated with the person.id_person ; the column client.name would be inserted in the column person.name, client.salary could be set by the user not to be associated with any column of the person table, but rather create that column as a new... That is, associate each column of a table to a column of another table, or create a new column in the second table, stating association with the association.

Does anyone have any idea/suggestion how to do it? The system is being made in PHP.

  • 2

    How about not doing any of this? At least in the way described, it seems very confusing not to achieve any goal. Of course there may be some reason, but it is not clear in the question, so I can only say to simplify and avoid doing so. With more information you could suggest something more precise. With questions without details you can only receive answers without details.

  • I agree with @bigown, don’t... Rethink your structure a little bit and why you have the same data in different tables? It would not be simpler just to say that the client table has the external key id_person ?

  • I agree with @bigown but another option, if using a table is not possible is to use a relationship table. Instead of struggling to merge data into tables with different structures, you can’t use a table just associating client.id and person.id_person and make the necessary relationships in the query?

  • I need to do a data integration process, that’s the reason. Two tables 'merged' that originate a new one. The previous two are removed after that and the new table is created on a new basis. That is, I copied the person table to the new repository, integrated. Now I need to add the client table data in this table.

  • You just want to select all the records from the previous database table and move the data up to a new table in a new database is this?

  • associating the previous table with the new one. The previous table will no longer exist?

  • Will you do the insertion at once? or is it every time the customer uses the system, you want it to happen gradually?

  • Only once, then the previous table will no longer exist. Taking the table from one base and inserting it into another table, from another base, is quiet. But I can not insert the entire table, precisely because the structure of the two is different...and some columns do not exist in the new table and others will not be populated ( Null) because they do not exist in the first table... That is, user would have to select a column of the first table and then select the column of the new table, in which you want to enter the data ( and an option to create a new column when n exists). only see this solution.

  • In other words, you will have to make a system for the user to manually register the records that do not match at that time. For example: it loops and goes out by logging... ai beats an incongruity and the user chooses whether to create a new column or use an existing column. Then the system keeps recording until it has some new incongruity... that’s it?

Show 4 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.