Technical Article

Reset Identity Seeds

,

This Script is used to reset the Identity coloumn to whatever the value we required. We need to compile this procedure in the database where we required to ressed the Identity coloumns of every table.
After compiling we need to execute this procedure with a parameter of integer value. Then it will reseed the Identity coloumns to the parameter value. For executing this procedure we need to use the syntax
"Exec AxSp_ReseedID @IntReseedValue".

For ex: Exec AxSp_ReseedID 100000
will reseed the Identity coloumn to 100000.

CREATE PROCEDURE AxSP_ReseedID (@IntReseedValue AS integer)

AS 
 
BEGIN
 DECLARE @tblName VARCHAR(100)
 DECLARE curReseed CURSOR 
 FOR SELECT [name] FROM sysobjects WHERE xtype = 'u' AND IDENT_INCR(NAME) IS NOT NULL 
 
 OPEN curReseed
 FETCH NEXT FROM curReseed INTO @tblName
 
 WHILE (@@fetch_status = 0)
 BEGIN
      DBCC CHECKIDENT(@tblName, RESEED, (@IntReseedValue)
      FETCH NEXT FROM curReseed INTO @tblName
 END
 
 CLOSE curReseed
 DEALLOCATE curReseed
 
END
GO

Rate

You rated this post out of 5. Change rating

Share

Share

Rate

You rated this post out of 5. Change rating