SQL Server改变自增列字段的初始值

改变自增字段的初始值
1。identity 函数中不能用变量作参数
declare @a int
select @a=190
select identity(int,@a,1) as id,* into #temp from tablename
select * from #temp
上述不正确,可以用如下方法
declare @a int
set @a=190
//首先把结构赋值过去
select identity(int,1,1) as id,* into #temp1from tablename where 1=2
//改变初始值
dbcc checkident(#temp1,reseed,@a)
insert into #temp1 select * from tablename
select * from #temp1
2。要想让自增字段从1开始,可以
dbcc checkident(tablename,reseed,0)

你可能感兴趣的:(数据库)