Reseed Auto Generated Id column in SQL SERVER

Dear friends,

Some time we need to reseed auto generated column values. To do this task we need to perform following action.

DECLARE @MaxId AS INT

 SELECT @MaxId = MAX(coursed)

FROM dbo.Courses

DBCC CHECKIDENT (Courses, RESEED, @MaxId)

 I hope this will help you.

 Thanks & Regards

Rajat Jaiswal

Advertisements

2 thoughts on “Reseed Auto Generated Id column in SQL SERVER

    1. Hi Ravindra,
      Sorry for such a late response.
      The DBCC CHECKINDENT is the command in which is use to reseed the column or id.
      The CHECKINDENT required 3 parameters

      1 ) ‘table_name’
      Is the name of the table for which to check the current identity value. The table specified must contain an identity column. Table names must comply with the rules for identifiers.

      2) “NORESEED /RESEED”
      Specifies that the current identity value should not be changed./Specifies that the current identity value should be changed.
      3) new_reseed_value
      Is the new seed value to use in reseeding the identity column.

      Thanks & Best Regards
      Rajat Jaiswal

      DBCC CHECKIDENT (Courses, RESEED, @MaxId)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s