I have a table with something around 300 records in SQL Server 2017 Express. Now the issue is that some of the records got the ID shifted by a 1000. I need to update the records to discount the 1000 added.
The problem is that (wrongly, I fully agree) this ID column is being used by the user of a system to identify orders. In that case, since this value is presented and used by the end user, they do not accept the skip. I fully agree it was a very wrong design when the system was created, but right now I need to correct the values.
So I would like to do something like:
Update table SET Id = Id - 1000 WHERE Id > 1000;
The issue is that the column is identity and SQL Server does not allow it to be updated.
I can set the value on insert via SET IDENTITY_INSERT table ON
but I cannot change.
So how can I correct the IDs if the update is blocked?
I've tried creating a column IdTemp
, copying the values to it and update it. Then I considered dropping the Id
column and making IdTemp
identity, but I don't see how to turn a new column to identity.
So how can I proceed?