how to increment integer Columns value by 1 in SQL

Varinder picture Varinder · Feb 15, 2012 · Viewed 221.9k times · Source

My questions is

how to increment a column's value by 1.

For example, suppose a column ID has values 1,2,3,4, ..

Now when I update this table then ID column should increment by 1,

Now ID will become 2,3,4,5, ..

Answer

gbn picture gbn · Feb 15, 2012

To add one to every value in the table...

UPDATE myTable
SET ID = ID + 1

To create a new value, one more then the previous highest (usually), use a column with IDENTITY