I have got an over 500 rows table with a column called ID which is of datetype INT. Currently the values are all NULL.
What I want to achieve is to populate the ID column with an incremental number for each row, say 1, 2, 3, 4, …, 500 etc.
Please give me a help with any idea how to achieve this by SQL script.
using
ROW_NUMBERin a CTE is one way, but here’s an alternative; Create a newid1column asint identity(1,1), then copy over to id, then drop id1:Result:
While you could also drop and recreate
IDas an identity, it would lose its ordinal position, hence the temporaryid1column.