Your technology certification is waiting. Enroll in Cloud Class ®
Declare @min_id int, @max_id int
-- Get the current min and max ID
SELECT @min_id = Min(id), @max_id = Max(id)
-- Insert the duplicate rows
INSERT INTO MyTable(ParentID)
-- New rewrite the ParentID's
SET ParentID = ParentID + (@max_id - @min_id)
WHERE id > @max_id
Open in new window
SELECT Id + 100 As id, ParentId
Create Table Table2(Id(int), ParentId(int));
Insert Table2(Id, ParentId)
Select Id + 100 As id, ParentId From Table1;
Update Table1 Set id = id +100;
Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.
Have a better answer? Share it in a comment.
Please enter a first name
Please enter a last name
Must be at least 4 characters long.
Join and Comment
From novice to tech pro — start learning today.
Premium members can enroll in this course at no extra cost.