Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 How to reuse the primary key of deleted record?

Author  Topic 

suanleba
Starting Member

1 Post

Posted - 2009-03-31 : 02:45:38
I have a website developed in visual web developer 2008, there has a database table, a column names APPID is set to primary key, if a record is deleted, it's APPID is saved into another table names Deleted_Table. the question is :
if one record is deleted, primary key of the deleted record can not be used when add in a new record, for example, I have total 10 records in my table, if record which primary key is 6 is deleted, when I add in a new record, I'd like use 6 instead of 11 (auto-generated by the system) as the primary key for the new add in record.

if I want to reuse the primary key of the very first record in the Deleted_table for a new inserted record all the times, how I can do it? I need details examples. anybody can help me on this.I am really urgent,thanks a lot.

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-03-31 : 03:08:09
dbcc checkident('tablename',reseed,0)
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-03-31 : 03:40:26
See blog post here http://weblogs.sqlteam.com/peterl/archive/2009/03/10/How-to-efficiently-reuse-gaps-in-identity-column.aspx


E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page
   

- Advertisement -