Patricio Treviño

Patricio Treviño

Husband . Father . Developer

Reset an identity column of a table in SQL Server

I use this to clean up my tables after completing development of a data-load script.

The reason... I keep deleting data from the table and re-running the script over and over again, and of course, the identity keeps getting bigger and bigger. At the end, the id of the first entry in the table has some ridiculous number and honestly...

I just can't have it.

Enjoy!

Syntax

DBCC CHECKIDENT (<table>, RESEED, <value>)
view raw syntax.text hosted with ❤ by GitHub

Option Description
table The name of the table to be reset.
value The new value to be used.

Example

DBCC CHECKIDENT ('Employee', RESEED, 1)
view raw example.sql hosted with ❤ by GitHub

References

DBCC CHECKIDENT (Transact-SQL)