I have an issue in insertion of records from one table to another the tables schema is same
Table 1
Id Parent Id Text
11 Null A
12 Null B
13 11 C
14 11 D
15 13 E
The record should be inserted in this format, According to my knowledge I have to copy the foreign key relation not the identities of it.
Table 2
Id Parent Id Text
31 Null A
32 Null B
33 31 C
34 31 D
35 33 E


Ronika JencyRank #770 · 3K reputationPosted Jun 5, 2019, 9:04 PM EDT
Umang Tandon108 reputationPosted Jun 6, 2019, 12:20 AM EDT
Both the tables have same schema same primary(ID) foreign key(ParentId) realtion.
The approach which I am currently using is recursive approach first insert the text and keep the parent id null and after this I will get the newly generated id in the new table and then I will update it (this part I am not able to understand that how i have to do) am I following the right approach?
Any help will be appreciated thanks.
Ronika JencyRank #770 · 3K reputationPosted Jun 6, 2019, 1:24 AM EDT
Umang Tandon108 reputationPosted Jun 6, 2019, 1:40 AM EDT
Ronika JencyRank #770 · 3K reputationPosted Jun 6, 2019, 2:09 AM EDT
Umang Tandon108 reputationPosted Jun 6, 2019, 3:57 AM EDT
Umang Tandon108 reputationPosted Jun 12, 2019, 3:38 AM EDT
I have found a solution to this question.
Steps: Insert the Text column values into the main table, leaving the ParentId as null and at the same time insert the values into a Dictionary as oldId key and New Inserted Id as value to the corresponding key.
After insertion Update the values on the basis of the mapped Dictionary keyValue Pair