设置现有字段自增

--设置自增
--逻辑:先创建新的相同表,然后将数据迁移到新表,删除旧表
create table t2 (
[CompanyID] int identity(1, 1) primary key,
[Plant] varchar(50)
,[Name] varchar(200)
,[IsValid] bit
,[ParentID] int
,[PlantLevel] int
,[Remark] varchar(2000)
,[PCCode] int
,[RootID] int
,[RootCompanyID] int
)
set identity_insert t2 on
insert into t2([CompanyID]
,[Plant]
,[Name]
,[IsValid]
,[ParentID]
,[PlantLevel]
,[Remark]
,[PCCode]
,[RootID]
,[RootCompanyID]) select * from [Company]
drop table [Company]
exec sp_rename 't2', 'Company'
set identity_insert [Company] off

原文地址:https://www.cnblogs.com/jxw-29/p/7553218.html