0
votes

I've got a problem, I need to merge 2 databases to one db.

Problem there are the same tables, but each tables got different field.

Example:

DB1 should merged to DB2

DB1 Table: xyz Fields: id, field1, field2 etc

DB2 Table: abc Fields: id, field1, field3 etc

If I try to insert SQL from DB1 to DB2, I got errors like "Column field2 not found"

Is there a tool which can help me merge these databases?

I tried it with MySQL Workbench, no success.

Thanks for your helping.

Greets Chris

1
(1) Show the query that is generating the error you are getting. (2) Are you confusing a "database" with a "table"? - Gordon Linoff
1) INSERT IGNORE INTO abc (field1, field2) VALUES ('asd','qwe') 2) I need to merge 2 Databases, but acutally i try it on table level - Chris
Try HeidiSQL, much better and easier than workbench, and free. I believe it will help you. make some tries before going to production table. - maytham-ɯɐɥʇʎɐɯ
I'll try it. Thanks =) - Chris

1 Answers

2
votes

There are several possible solutions.

If the column names are different, you may not want to merge them at all, as the data are probably different.

But still if you want to merge them, be sure to make same columns in source and target tables. You can do this during INSERT by specifying the column names.

INSERT INTO xyz (field1, field2) SELECT field1, field3 FROM abc;

Notice that the field2 will have the values of field3.

Other option is to make both the tables have same name, if you are handling this data once in a lifetime. Then use same column names.

Either rename the columns or add the columns - so that both source and target tables appear similar.