Click here to Skip to main content
15,889,200 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi friends,

I deleted the record from existing table which primary key column created with identity method. after deleting record when i enter the new record to table than it identity taken from the next value of last deleted.but i want to reset them from first value. how can i do it

Thanks in advance
Posted

DBCC CHECKIDENT (MyTable, RESEED, 1) will reset the index on your table
 
Share this answer
 
While you can use DBCC to re-seed the primary key column value, I think this shouldn't be done. One characteristics of a surrogate key is that the key value itself is meaningless, it's just unique. This is exactly what identity does.

When a surrogate key is used, there is no quarantee that all the numbers are present (and there shouldn't be no quarentee).

For example if you have 100 rows and the kay values are from 1 to 100, consider what happens when record 78 is deleted. Now there's a hole in the sequence, but if you reseed the identity to 78 to get the missing value, the next inserts will fail since records 79, 80 and so on already exist.
 
Share this answer
 
hi try this

SQL
The following line resets the Identity value for the table to 0 so that the next record added starts at 1.

DBCC CHECKIDENT('Tablename', RESEED, 0)


regards
sarva
 
Share this answer
 

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