07-20-2023, 02:20 PM
Although most answers are suggesting RESEED to 0, many times we need to just reseed to next Id available
declare @max int
select @max=max([Id]) from [TestTable]
if @max IS NULL --check when max is returned as null
SET @max = 0
DBCC CHECKIDENT ('[TestTable]', RESEED, @max)
This will check the table and reset to the next ID.
declare @max int
select @max=max([Id]) from [TestTable]
if @max IS NULL --check when max is returned as null
SET @max = 0
DBCC CHECKIDENT ('[TestTable]', RESEED, @max)
This will check the table and reset to the next ID.