Wednesday, February 26, 2014

SQL - Reset Identity Column Value to Start With 1 in SQL Database

 SQL - Reset Identity Column Value to Start With 1 in SQL Database 


Here I will illustrate how to reset  identity column value in SQL server or change or rest identity column value to start with 1 in SQL server. Then again reseed identity column value in SQL server.

After setting identity property on particular column I inserted few records in Sql Database table and
that value automatically increase whenever I inserted data that would be like this 


 


 Ex: Above table contains total 6 records after delete all these records if I insert new record CountryID value
 will start from 7.

For reset identity column value and start value from “1” during insert new records we need to
write query for reset identity column value. Check below Query

DBCC CHECKIDENT (Table_Name, RESEED, New_Reseed_Value)

Table_Name is name of your identity column table like tbl_Country

RESEED
specifies that the current identity value should be changed.

New_Reseed_Value is the new value to use as the current value of the identity column like CountryID. 



 EX: DBCC CHECKIDENT ('tbl_Country', RESEED, 0) 

Once we run the above query it will reset the identity column(CountryID) value in tbl_country
table and starts identity column value from “1”