Rebooting of SQL Server causes "sequencing issues"

jamesmetcalf74
jamesmetcalf74 used Ask the Experts™
on
We have an app that has "application numbers"
every time we reboot the sql server, the next submitted application breaks the previous sequence by 1000.

the support people have identified the problem as an identity column issue and say that sql server is acting the way it should.
they say that identity columns reserve a pool of 1000  numbers and when it reboots, it jumps the sequencing by a thousand.
I reboot this server monthly and this is causing a problem.
Their recommended fix sounds to cumbersome to me which was running about 7 scripts to reset the pool identity everytime the sql restarts.

They also pointed out this article that sounds pretty reasonable but I would like someone to confirm the logic in the article posted before I try either one of the suggested solutions.
http://www.dfarber.com/computer-consulting-blog/2014/2/13/how-to-solve-identity-problem-in-sql-2012.aspx

can someone verify?
Does anyone else have a better solution?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Paul MacDonaldDirector, Information Systems
Commented:
"...they say that identity columns reserve a pool of 1000  numbers and when it reboots, it jumps the sequencing by a thousand."
This is accurate, and a useful feature if you're caching data anywhere between the SQL Server and your storage device.  Since an identity field should only be used to provide uniqueness to a row, having it skip values should cause little or no disruption in your use of the table anyway.
Scott PletcherSenior DBA
Most Valuable Expert 2018
Top Expert 2014
Commented:
You could easily use a start-up proc to reset the identity to the last actual value in the table(s).  Then you wouldn't skip any numbers.  If you want to pursue this, let me know and I can provide more details.

Author

Commented:
I would like to request that Scott.
Thanks a ton
Senior DBA
Most Valuable Expert 2018
Top Expert 2014
Commented:
See below.  Naturally change 'user_db_name' and 'table_name'/'table_name2' to your actual db and object names.
USE master
GO
CREATE PROCEDURE SQL_Startup
AS
SET NOCOUNT ON;
--make sure deadlock trace flag is set
DBCC TRACEON ( 1222, -1 );
--reset identity value to last-used number, so no numbers are skipped
EXEC('USE [user_db_name];
DECLARE @max_identity_value bigint;
SELECT @max_identity_value = MAX($IDENTITY)
FROM dbo.table_name;
DBCC CHECKIDENT(''dbo.table_name'', RESEED, @max_identity_value);
SELECT @max_identity_value = MAX($IDENTITY)
FROM dbo.table_name2;
DBCC CHECKIDENT(''dbo.table_name2'', RESEED, @max_identity_value);
')
GO --end of proc
EXEC sp_procoption 'SQL_Startup', 'startup', 'on'

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial