Jump to content

Data Migration Script


anujgarg

Recommended Posts

Hi,

 

I am writing a data migration PHP script. I have a table with following structure:

 

id parent_id

1    0

2    0

3    2

4    3

 

This table data needs to be migrated in a different table that already contains some record. So, the ids will be different here (lets say following):

 

id parent_id

10    0

11    0

12    2

13    3

 

But, as we are seeing the parent_id is same in new table. Here comes my problem. I want to change the parent_id according to modified (new) id in new table. How can it be possible?

 

Please suggest...

 

All suggestions will be highly appreciated.

 

Regards,

Anuj

Link to comment
https://forums.phpfreaks.com/topic/199465-data-migration-script/
Share on other sites

This is probably not the best way and is purely hypothetical. Perhaps you could port it over with an extra column for old_id then run a query along the lines of...

 

UPDATE table t1 SET parent_id = (SELECT id FROM table t2 WHERE t2.old_id = t1.parent_id)

 

You could then drop the old_id column if it's no longer required.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.