Azerbaijani | English | Persian | Turkish

Blog categories

How to set start value for column with autoincrement

Hi

 

We have a table tbl_Posts with  The Id column that is set to autoincrement(1,1).

And we want to have the autoincrement field start from a defined value.

 

Retrieving the identity for the table tbl_Posts

DBCC checkident ('tbl_Posts') 

Repairing the identity seed (if for some reason the database is inserting duplicate identities):

  DBCC checkident ('tbl_Posts', reseed)

Changing the identity seed for the table tbl_Posts to 500: 

DBCC checkident ('tbl_Posts', reseed, 500) 

The next row inserted will begin at 501.

 

Keywords