SQL increment a number SQL increment a number sql sql

SQL increment a number


I think you could do it easily with this:

UPDATE your_tableSET id = id + (SELECT MAX(id) FROM your_table)


Wouldn't it be easier to just take the maximum and add it to this ID column? (Remember: the ID column can't be an identity column, otherwise an update will fail)

DECLARE @MAXID INTSELECT @MAXID = MAX(ID) FROM #WorkingTableUPDATE #WorkingTable SET ID = ID + @MAXID


Please Try this Code:

Declare @count int = 0UPDATE tableSET @count = code = @count + 1