I have two identical tables that are located in two identical databases (with a different name). I want to combine these two tables, but their primary keys are used in other tables,
these tables are as follows:
Table a
id column1 column2 column3 ___ ________ _______ ________ 1 text text text 2 text text text 3 text text text
Table B
id column1 column2 column3 ___ ________ _______ ________ 2 text text text 3 text text text 4 text text text
tables related to table A
Link A
id column1 tableA_ID ___ ________ _______ 1 text 2 2 text 3 3 text 4
Link B
id column1 tableA_ID ___ ________ _______ 1 text 3 2 text 3 3 text 2
Please note: the tables have identical id , this means that when I do the merge, I need to change the id second table. Remember that the primary keys of the second table are used in other tables.
I wrote this query to combine two tables:
INSERT INTO db_A.`Table_A`(`column2`,`column3`) SELECT `column2`,`column3` FROM db_B.`Table_B`;
This query will correctly copy the records of the second table to the first table.
Now I want to also move the data of the tables associated with Table B , I can use the same query, but now the foreign key will not match, since the id associated with it has been changed.
How to update them so that id again?
NB: I have no ON UPDATE CASCADE restrictions for these tables
I hope this makes sense, I will try to improve this issue so that everyone understands it.
Database Information
Type : MySQL Engine: MyISAM