Pages

Friday, November 6, 2020

SQL Server: My AutoIncrement Column is Skipping Values (solved)

There is a long explanation about SQL server caching values for autoincrement columns, and losing them when the server is restarted, but the fix is this:


USE [database_name]
ALTER DATABASE SCOPED CONFIGURATION SET IDENTITY_CACHE = OFF
GO

This does incur a performance hit, so if you're inserting 20 billion records a day, be warned.  But for a normal web or app database, this will make it more likely that your autoincrement values will step up the way you had intended.

...


Bryan Valencia is a contributing editor and founder of Visual Studio Journey.  He owns and operates Software Services, a web design and hosting company in Manteca, California.

Share This!

Contact Us

Name

Email *

Message *