How can I set a Microsoft SQL field as identity but to START with a certain number?

delete picture delete · Mar 31, 2010 · Viewed 20.2k times · Source

How can I set a Microsoft SQL field as identity but to START with a certain number?

Answer

Oded picture Oded · Mar 31, 2010

In SQL Server, when you declare the column as an IDENTITY column, you specify a seed and increment.

The seed value is the number to start from, the increment is the amount to increment for the next number.

In this example, you start with 100, incrementing by 1:

column INT NOT NULL IDENTITY (100, 1)

If you want to change it for an existing table (so new records start from a different range), use DBCC CHECKIDENT.

In this example, the table dbo.myTable will start with a new seed of 300:

DBCC CHECKIDENT ("dbo.myTable", RESEED, 300);