DBCC CHECKIDENT - Check and/or reseed the current identity value for a table.

Syntax
      DBCC CHECKIDENT
        ( 'table'
           [ , { NORESEED | { RESEED [ , new_reseed_value ] } } ]
        ) [WITH NO_INFOMSGS]

 Key:
   NORESEED     -  The current identity value should not be changed.
   RESEED       -  Change the identity value.
   new_reseed_value - The new seed value to be used for the identity column.
   WITH NO_INFOMSGS - Suppresses all information messages.

Example

-- Reset the current identity value
USE MyDatabase;
GO
DBCC CHECKIDENT ('MySchema.MyTable', RESEED, 5000);
GO

If the identity column value has jumped or incremented by around 1000, this may be due to a bug in IDENTITY_CACHE. You can reset the value using DBCC CHECKIDENT after first deleting any rows with the new/high values.

Then prevent a reocurrence by turning off IDENTITY_CACHE, this is likely to lower the performance:

USE MyDatabase;
GO ALTER DATABASE SCOPED CONFIGURATION SET IDENTITY_CACHE = OFF GO

I finally got it all together and now I forgot where I put it! ~ anon

Related commands

DBCC CHECKCONSTRAINTS - Check integrity of table constraints.

Equivalent Oracle command:

SELECT Sequence_for_my_Table.currval into CurrIdentity from dual;


 
Copyright © 1999-2024 SS64.com
Some rights reserved