Changing Identity starter to a specific value

c00012 741 Reputation points
2020-11-19T06:39:34.083+00:00

Hello,

I've got a question about identity seed.

I've got a table as follows:
41044-ice-screenshot-20201119-153632.png

I want to change identity seed from 1 to 1000. Any solutions?
Thanks for the answer in advance.

seihyung

Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,691 questions
{count} votes

Accepted answer
  1. Cris Zhan-MSFT 6,646 Reputation points
    2020-11-19T07:31:21.93+00:00

    Hello @c00012 ,

    The IDENTITY column can only be set when the table is created, or alter the table add a new IDENTITY column. Actually you cannot alter the existing identity column in a table like other regular columns ( alter table alter column...).

    You may need to use the DBCC CHECKIDENT('tableName', RESEED, NEW_RESEED_VALUE) to update the Identity column value for new records .
    This will change the current seed value of the identity column of the specified table.
    If you need to insert specific identity values, you can SET IDENTITY_INSERT ON in your insert statement.

    In addition, if need to update the Identity column value for existing records, you can drop the IDENTITY column and re-add.(It is recommended to test in the test environment before applying to production. I tested it in a table with 100,000 records and everything is fine).
    Or create a new table with IDENTITY(1000,1) then insert data.


1 additional answer

Sort by: Most helpful
  1. Ronen Ariely 15,201 Reputation points
    2020-11-19T07:29:29.793+00:00

    Hi,

    You can also use DBCC CHECKIDENT to manually set a new current identity value for the identity column.

    https://learn.microsoft.com/en-us/sql/t-sql/database-console-commands/dbcc-checkident-transact-sql?view=sql-server-ver15

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.