Create Auto Increment ID in Table with data
Step 1
Create new Column as ID in Table with data type INT.
Step 2
Update table with below query .
;WITH cte AS
(
SELECT *, RowNum = ROW_NUMBER() OVER (ORDER BY GETDATE())
FROM TableName
)
UPDATE cte
SET ID = RowNum + 1
WHERE (RowNum = RowNum)
Step 3
Modify the ID column Identity (1,1)
Comments
Post a Comment