php - Copy records and related records over in a MySQL database (stored procedure or function) -


i thinking stored procedure/function best solution this, open suggestions.

i want duplicate master record, , duplicate of associated records @ same time. consider following example setup:

table 1    table 2     table 3 -------    ----------  ---------- id (pk)    id (pk)     id (pk) data1      t1_id (fk)  t2_id (fk) data2      data1       data1 data3      data2       data2 

looking @ schema above, can see table 1 master table. want copy that, along child records in table 2 , grandchild records in table 3.

when done, pk's (of auto_increment, , dynamically generated) need updated. when happens, foreign keys in related tables need updating also.

is there stored procedure/function can ease compared trying now? [select multidimensional array, , foreaching, foreaching, foreaching , more foreaching on data inserts , whatnot].


Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

gradle error "Cannot convert the provided notation to a File or URI" -

python - NameError: name 'subprocess' is not defined -