SQL Numbering a table in sequence without IDENTITY

This is for renumbering of the rows in a table with out IDENTITY.

-- add a rowid to the table
ALTER TABLE #table_name
ADD rowid int null
-- set the rowid vales to zero
UPDATE #table_name
SET rowid = 0
-- declare a variable to increase
DECLARE @rowid int
SET @rowid = 0
-- update the table
UPDATE #table_name
SET @rowid = rowid = @rowid + 1

Cup size   
Select size then click on coffee cup.
This entry was posted in Code, Snippets, SQL. Bookmark the permalink.