I have a table with this structure:
[ID] [int] IDENTITY(1,1) NOT NULL,
[ParentID] [int] FOREIGN KEY([ParentID]) REFERENCES [dbo].[tblTask] ([ID])
[Name] [varchar](20)
This table is populated.
I need to import data from another similar table, and need the new parent-child relationships to be valid of course. Is there some pre-existing functionality or methodology that I can use?
This is MSSQL 2008
From the comments it seems you are doing this import in an environment where you don’t have to consider other concurrent inserts.
So in this case you can just
SET IDENTITY_INSERT ONthen apply an offset to the source ids so they will end up larger than any pre-existing ids in the destination table.