SQL Server 2012 check identity jump number after restarting service

Copyright: copy, please indicate the source https://blog.csdn.net/weixin_39392627/article/details/86654871

env:Windows Server 2016

       SQL Server 2012 SP1

A friend recently asked me a question, identity issues after the jump, the SQL Server service is restarted.

I remember SQL Server 2008R2 have encountered remember is to use script to find the number before the restart service reset, but this way at the time of multi-table is a great burden.

Trace flag 272 is a solution.

 

1. Create a test DB

command:

CREATE DATABASE [TBTEST02]
 CONTAINMENT = NONE
 ON  PRIMARY 
( NAME = N'TBTEST02', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL11.SQL2012\MSSQL\DATA\TBTEST02.mdf' , SIZE = 4096KB , FILEGROWTH = 1024KB )
 LOG ON 
( NAME = N'TBTEST02_log', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL11.SQL2012\MSSQL\DATA\TBTEST02_log.ldf' , SIZE = 1024KB , FILEGROWTH = 10%)
GO

 

2. Create a test table with data

command:

CREATE TABLE dbo.TEST01 (id int identity, name varchar(20))

insert into dbo.TEST01(name) values('john'),('mary')

select * from dbo.TEST01

 

3. Check the identity information

command:

dbcc checkident('TEST01', NORESEED)

identity value now is 2

 

4. Restart the SQL Server service, and the addition of new test data

command:

insert into dbo.TEST01(name) values('sean'),('larry')

select * from dbo.TEST01

Skip condition occurs after restarting

 

5. Test Trace flag 272, added to the startup parameters, and restart the SQL Server service

 

6. Check start identity value

command:

dbcc checkident('TEST01', NORESEED)

identitt value 1003

 

7. Increase the test data

command:

insert into dbo.TEST01(name) values('sean'),('larry')

select * from dbo.TEST01

Identity configuration value 1004, 1005

If there are multiple tables have identity jump number problem, Trace flag may be a good choice, must be placed inside the boot parameters will be effective.

Or the use of script re-set

 

Guess you like

Origin blog.csdn.net/weixin_39392627/article/details/86654871