0

I have two exactly same set of data (two separate databases) and I'd like to join them into one database. The tables are shown in the picture below. I cannot just export the data from one database and import to other database because I would get unique primary key violations.

Both databases have following tables:

enter image description here

How could I update primary keys of one database, that the primary keys are changed in the junction tables as well. Eg how to add 1000 to all the primary keys in whole the database. Or if there is any other approach I could use to import the data from one database to another with all the relations

LukaB
  • 17
  • 1
  • 6
  • strictly sql...? – Black.Jack Jan 30 '18 at 12:51
  • yes I'm looking for SQL command that could update the primary keys (tables and related tables) or to import the data from one database to another – LukaB Jan 30 '18 at 13:00
  • maybe this is for you https://stackoverflow.com/questions/41461412/how-to-update-primary-key-value-in-sql – Black.Jack Jan 30 '18 at 13:04
  • If you can revise foreign key, you can drop the original foreign key and re-create the foreign key with original setting and add the option **ON UPDATE CASCADE**. You can update primary key in parent table and the referenced columns will be update at the same time. Otherwise, using `SET FOREIGN_KEY_CHECKS = 0;` to disable consistency verification. Then update every primary key columns and referenced columns manually. – Wilhelm Liao Jan 30 '18 at 13:27
  • Thank you @WilhelmLiao will try that, ON UPDATE CASCADE seems to be a good solution – LukaB Jan 31 '18 at 14:32

0 Answers0