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

scsnsjsl_cs_dn 2015-04-15 07:48:53
有表A,其中字段ID为identity(1,1)
目前最大值为100

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

比如:上一条插入语句,记录为1024,
下一条插入语句的ID就为1026了
...全文
150 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
还在加载中灬 2015-04-15
  • 打赏
  • 举报
回复
如上所说,种子值可以用 CHECKIDENT修改,增量值改不了 只能重建,可以重建表也可以重建列,然后再导数据
卖水果的net 版主 2015-04-15
  • 打赏
  • 举报
回复

-- 表,必须删除重建,再通过 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

34,591

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧