create table tb(id int, ident int identity(10000, 1)) insert into tb select 1000 union all select 1001 union all select 1002 union all select 1003 DBCC CHECKIDENT('tb', RESEED, 20000)insert into tb select 1004 union all select 1005 union all select 1006 union all select 1007 select * from tb drop table tb结果: id ident 100 10000 101 10001 102 10002 103 10003 104 20001 105 20002 106 20003 107 20004
方法如下: 1.先将自增列修改为不自增,否则无法更新, 2,用以下代码就可实现,比如改为从1001开始,declare @i int set @i=1000update shengchandan_master set rowid=@i,@i=@i+1 3,再将那个列修改成自增
先删除,再加入create table #tb(id int, ident int identity(10000, 1)) insert into #tb select 1000 union all select 1001 union all select 1002 union all select 1003 alter table #tb drop column identalter table #tb add ident int identity(20000,1) select * from #tb
create table tb(id int, ident int identity(10000, 1)) insert into tb select 1000 union all select 1001 union all select 1002 union all select 1003 DBCC CHECKIDENT('tb', RESEED, 20000)insert into tb select 1004 union all select 1005 union all select 1006 union all select 1007 SELECT * FROM tb ------------------------ id ident ----------- ----------- 1000 10000 1001 10001 1002 10002 1003 10003 1004 20001 1005 20002 1006 20003 1007 20004(所影响的行数为 8 行)
insert into tb
select 1000 union all
select 1001 union all
select 1002 union all
select 1003 DBCC CHECKIDENT('tb', RESEED, 20000)insert into tb
select 1004 union all
select 1005 union all
select 1006 union all
select 1007 select * from tb
drop table tb结果:
id ident
100 10000
101 10001
102 10002
103 10003
104 20001
105 20002
106 20003
107 20004
1.先将自增列修改为不自增,否则无法更新,
2,用以下代码就可实现,比如改为从1001开始,declare @i int
set @i=1000update shengchandan_master
set rowid=@i,@i=@i+1
3,再将那个列修改成自增
insert into #tb
select 1000 union all
select 1001 union all
select 1002 union all
select 1003 alter table #tb
drop column identalter table #tb
add ident int identity(20000,1)
select * from #tb
只有先删掉再加上去,就像LS的
add ident int identity(20000,1)
都可以!
insert into tb
select 1000 union all
select 1001 union all
select 1002 union all
select 1003 DBCC CHECKIDENT('tb', RESEED, 20000)insert into tb
select 1004 union all
select 1005 union all
select 1006 union all
select 1007 SELECT * FROM tb
------------------------
id ident
----------- -----------
1000 10000
1001 10001
1002 10002
1003 10003
1004 20001
1005 20002
1006 20003
1007 20004(所影响的行数为 8 行)
不过可能会引起重复