Archive for April, 2007

Current identity value is reset after delete the record

Posted in Sql Server 2000, Sql server 2005 on April 3, 2007 by bimal4u

Create procedure DeleteTest(@ID int)
as
begin
 declare @cnt int 
 
 — delete current record
 delete from newTest where id=@ID

 — reset identity value to the total records in the table
 select @cnt = isnull(max(ID),0) from newTest
 DBCC CHECKIDENT ( ‘dbo.newTest’, RESEED, @cnt) 

————-

For your reference  http://msdn2.microsoft.com/en-us/library/ms176057.aspx