Last active
February 17, 2019 14:06
-
-
Save hoggren/225ee6b949eac6675cf4815f3502333c to your computer and use it in GitHub Desktop.
SQL Snippets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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