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 t 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.

No comments:

Post a Comment

How to Auto-generate Order Line Item numbers for bulk uploads

 I had a problem where I had 17000 line items to insert into 9000 orders. The system required line item numbers, preferably numbered 1throug...