.Maui Blog

Reseed to next Id available in SQL Server

DECLARE @MaxId INT
SELECT
    @MaxId = max([Id])
FROM
    [MyTable] if @MaxId IS NULL
SET
    @MaxId = 0 DBCC CHECKIDENT ('[MyTable]', RESEED, @MaxId)
Exit mobile version