Here is the sample demonstration for reset identity column value:
Step 1: Create table.
- CREATE TABLE dbo.Emp
- (
- ID INT IDENTITY(1,1),
- Name VARCHAR(10)
- )
Step 2: Insert some sample data.
- INSERT INTO dbo.Emp(name)
- VALUES ('Rakesh')
- INSERT INTO dbo.Emp(Name)
- VALUES ('Rakesh Kalluri')
When we run above query the second insert statement will failed because of varchar(10) length.
Step 3: Check the identity column value.
Even second insert was failed but the identity value is increased .if we insert the another record the identity value is 3.
- INSERT INTO dbo.Emp(Name)
- VALUES ('Kalluri')
-
- SELECT * FROM Emp
Step 4: Reset the identity column value.
- DELETE FROM EMP WHERE ID=3
-
- DBCC CHECKIDENT ('Emp', RESEED, 1)
-
- INSERT INTO dbo.Emp(Name)
- VALUES ('Kalluri')
-
- SELECT * FROM Emp