Click here to Skip to main content
15,890,579 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I Wanted to set the Identity field back to 1 not affecting the database schema.
Any suggestion .
Please comment ...
Thanks In advance ....
Posted

SQL
DBCC CHECKIDENT('[table_name]', RESEED, [new_reseed_value])
-- for example
DBCC CHECKIDENT('tblUserMaster', RESEED, 0)
 
Share this answer
 
The only way to reset an identy field is to commit a TRUNCATE command on the table (but beware! this will clear all the records in the table as well).
But it will not be allowed if this identity column is used as a foreign key in another table; so you have to drop every foreign key relation based on this primary column first.

Why do you care about the values of your identity fields? Technically, you should not, unless you are getting short on new id's. An identity field is technically something managed by your database engine; trying to interact with it is at least a loss of time, at most a nonsense.
 
Share this answer
 
v2
This query will reset you Identity field back to 0, so that the 1st value entered into the table will have an identity value of 1.

... hope it helps

SQL
DBCC CHECKIDENT (your_table_name, RESEED, 0)
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900