Skip to content

Instantly share code, notes, and snippets.

@hoggren
Last active February 17, 2019 14:06
Show Gist options
  • Save hoggren/225ee6b949eac6675cf4815f3502333c to your computer and use it in GitHub Desktop.
Save hoggren/225ee6b949eac6675cf4815f3502333c to your computer and use it in GitHub Desktop.
SQL Snippets
/**
* Reset identity counter to next value - for example after deleting rows
*/
DECLARE @max INT
SELECT @max = MAX(ID)
FROM [dbo].[tablename]
IF @max IS NULL
SET @max = 0
DBCC CHECKIDENT ([dbo].[tablename], RESEED, @max);
/**
* Check current identity value, without changing it
*/
DBCC CHECKIDENT ([dbo].[tablename], NORESEED);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment