I need to make a copy of a row in a table and also copy all the rows that link to it via its foreign key in other tables. And then copy all the rows that link to these rows.
The problem is when I make a copy of the row the key is going to change. How can I propagate these changes through the relationships between tables?
You can write a stored procedure which implements all the copy logic.
Essentially:
store new ID in variable
copy of each row in child tables,
referencing FK in variable. Store the ID of the child row in variable2
In short, write a stored proc that starts at the top and walks down as many tables as needed.