I have an Identity
column in a SQL Server table.
When the Identity
column reaches the value 100, and then if I insert a new record in table, it would be 101.. But in my table it jumps to 10001, I don't know why this happens?
Plz help
I have an Identity
column in a SQL Server table.
When the Identity
column reaches the value 100, and then if I insert a new record in table, it would be 101.. But in my table it jumps to 10001, I don't know why this happens?
Plz help
This would happen when a bulk insert is done and rolled back. Assuming your column is defined as IDENTITY(1,1)
, try this code
-- Returns current Identity Value
DBCC CHECKIDENT ('YourTable', NORESEED);
This will return a message
Checking identity information: current identity value 'xxx', current column value 'xxx'. DBCC execution completed. If DBCC printed error messages, contact your system administrator.
Now run the following query
-- Resets the current Identity value to maximum value
DBCC CHECKIDENT ('YourTable', RESEED, 100);
The next insert must pick up from 101