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

解决方案 »

  1.   

    while exists(select 1 from a where 主键 not in(select 主键 from b))
    begin
          set rowcount 1
          insert b select * from a
          set rowcount0
    end
      

  2.   

    你好vivianfdlpw,我试了,造成死循环
      

  3.   

    while exists(select 1 from a where 主键 not in(select 主键 from b))
    begin
          set rowcount 1
          insert b 
          select * from a where 主键 not in(select 主键 from b)
          set rowcount0
    end