Introduction
An Identity column in SQL Server can be used for generating identity values of a table. SQL IDENTITY property on a column is used to generate an IDENTITY column. The Identity column takes two values, seed, and increment. Each new value is generated based on the current seed & increment.
IDENTITY [ (seed , increment) ]
Here seed is the value that is used for the very first row loaded into the table, and increment is the incremental value that is added to the identity value of the previous row that was loaded.
Here is the sample demonstration for resetting identity column values in SQL Server.
Step 1. Create a 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 the above query, the second Insert statement will fail because of the varchar(10) length.
Step 3. Check the identity column value.
DBCC CHECKIDENT ('Emp')

Even though the second insert failed, the identity value is increased; if we insert 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


Sibi BabuPosted Jun 19, 2023, 7:51 AM
In your solution where is the solution for resetting the Identity? You have shown every query for insert and delete. No solution for resetting the count from 1
hicham essaidiPosted Sep 1, 2021, 4:11 PM
Some thing like this will do the job, just make sure to use it as a trigger or something: delete from EMP where ID > 3; if exists (select * from EMP) begin declare @lastID int; set @lastID = (select top 1 ID from EMP order by ID desc); end else begin set @lastID = 1; end DBCC CHECKIDENT ('EMP', RESEED, @lastID)
Christian CamposPosted Jan 30, 2019, 5:06 AM
The problem is that SQL Server adds 1000 (or 10000 on bigint) in int identity column when the service restart.
Ismail Hakki SenPosted Nov 2, 2014, 8:09 AM
thanks but what if we have thousand records? we can't delete every rows and insert them again!