Monday, October 17, 2011

Reset IDENTITY field

Let us say you have an an IDENTITY field in your table in SQL Server, and have deleted all rows from it, and now wish to insert fresh data. But on doing so, you would notice that this table still remembers the identity value of the last row inserted into it. To start afresh, you would need to do an identity reset. And here is the syntax to do it
DBCC CHECKIDENT (tablename, RESEED, currentvalue)

So, if you want your orders table's identity field to start from 1, you need to use this as
DBCC CHECKIDENT (orders, RESEED, 0)

Reference: http://www.howtogeek.com/howto/database/reset-identity-column-value-in-sql-server/

No comments:

Post a Comment