Auto number fields

拥有回忆 提交于 2020-01-03 06:41:10

问题


I have a field in my SQL Server 2008 table that is auto number incremental of 1 and has over 100,000 records in it.

We are migrating servers at the moment so I'm looking at doing a little spring cleaning and will be deleting all the records from this table.

I still want the auto number incremental of 1 facility but I would like the first record to start at 102001, is this possible.

Thanks.


回答1:


Yes, simply set the start value of IDENTITY to be your chosen number. Syntax: IDENTITY (seed,increment)

CREATE TABLE Customers
(
  CustomerID int IDENTITY(102001, 1),
  Name nvarchar(MAX)
)



回答2:


I have used this TSQL command in the past to re-seed an auto number column in a table

 DBCC CHECKIDENT ('dbo.TABLE', RESEED, 102001)


来源:https://stackoverflow.com/questions/4670020/auto-number-fields

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!