I added a new identity column, and I need to update it so that the id column goes into the identity column, then delete the old id column and rename the identity column, because you cannot change a column to an identity.
I don’t know how to do this, I guess I want to loop through each row, insert it into the same table, setting the identity field to match the id field (using IDENTITY_INSERT) but I am not familiar with loops in SQL. Any ideas?
You could do it with temp table something like this:
Sample table and data
Add NewID as identity and get the value from OldID.