Skip to content
Advertisement

SQL Copy row in a table with relations

Hope some one can help me, I would like to copy rows in same table and that table has relation to another table that I have to copy related row accordingly:

Table1

I copied rows with table0Id = 3

Table1

I would like to do the same to Table2 depending to the Table1 Ids like this:

Table2

Table2

As you see row 1 and 2 are copied in table2 but they have new Ids from newly added rows in table1. I know how to do the firs part but I’m stuck at the second part.

Advertisement

Answer

Thanks for your answers, I figured it out like this by using output and identity:

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement