declare @i int
set @i=1
alter table 表a add sid int identity(1,1)
while @i<=(select count(*) from 表a)
begin
insert #b (字段列表)
select 字段列表 where sid=@i
set @i=@i+1
end
alter table 表a drop column sid
go
set @i=1
alter table 表a add sid int identity(1,1)
while @i<=(select count(*) from 表a)
begin
insert #b (字段列表)
select 字段列表 where sid=@i
set @i=@i+1
end
alter table 表a drop column sid
go
begin
set rowcount 1
insert b select * from a
set rowcount0
end
begin
set rowcount 1
insert b
select * from a where 主键 not in(select 主键 from b)
set rowcount0
end