Resetting Autoincrementing PK's

Posts   
 
    
Seth avatar
Seth
User
Posts: 204
Joined: 25-Mar-2006
# Posted on: 03-Feb-2009 08:19:55   

Friends: I run a routine that clears a database using the DeleteEntitiesDirectly. Is there a way to make the SQL Server autoincrementing PK's to reset back (so adding a new record does not increase the previous PK before deletion) through the API?

I am using SQL Server and v2.6

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 03-Feb-2009 09:26:41   

I think you'll have to call a SPs for this one to Truncate the tabel, or maybe an after delete Trigger, which checks on the count of records and if Zero, it truncates the table.

Anyway the following is a good chat, which I find relevant to your question: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=4025 Which also suggests the use of a GUID instead of the Identity, in case you only wanted to truncate the table in fear of a future overflow.