当前位置: 代码迷 >> Sql Server >> 高分请问:求修改自增长字段增量sql 语句,详见帖子
  详细解决方案

高分请问:求修改自增长字段增量sql 语句,详见帖子

热度:46   发布时间:2016-04-24 09:12:16.0
高分请教:求修改自增长字段增量sql 语句,详见帖子
有表A,其中字段ID为identity(1,1)
目前最大值为100

在保留原数据的前提下:
是否有sql 语句使ID字段每次由递增1变为递增2

比如:上一条插入语句,记录为1024,
下一条插入语句的ID就为1026了

------解决思路----------------------

-- 表,必须删除重建,再通过 insert select 方式把数据导过来
create table test(id int identity(100,1) , name varchar(10))
go
insert into test(name) values('zhangsan1')
insert into test(name) values('zhangsan2')
insert into test(name) values('zhangsan3')
go
create table test_temp(id int identity(100,2) , name varchar(10))
go
set identity_insert test_temp on
insert into test_temp(id,name) select id , name from test
set identity_insert test_temp off
go
drop table test
go
sp_rename 'test_temp', 'test', 'object' 
go
insert into test(name) values('lisi')
insert into test(name) values('wangwu')
go
select * from test 
go
-- drop table test 
go


------解决思路----------------------
如上所说,种子值可以用 CHECKIDENT修改,增量值改不了
只能重建,可以重建表也可以重建列,然后再导数据
  相关解决方案