importing data with updated parent-child keys
I have a table with thi开发者_如何学Pythons 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 ON
then apply an offset to the source ids so they will end up larger than any pre-existing ids in the destination table.
精彩评论