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

Popular posts from this blog

Convert HtmlToPDF in ASP.net & iTextshrap

Create Pivot Table In C#

How to Display Page Wise Total Amount & Grand Total Amount in Last page SSRS & RDLC Report