sqlserver2000复制表数据的问题~急!

时间:2022-03-01 19:16:06
sqlserver2000能不能将一张表中第五行到第一百行,再从第一百零五行到二百行的数据复制到另外一张表中?表结构相同,数据类型相同未建索引等,需要的话可以另建索引。

3 个解决方案

#1


如果建了聚集索引,是可以的,价格具有顺序的id列,然后再获取你那些范围再插入。

#2


select id=identity(int,1,1) into #t from tb 
insert into tb2
select * from #t
where id between 5 and 100

如果你要编程实现的话,需要使用循环,并且要插入数据的表名是有规律的

declare @i int 
set @i=0
while (条件自己写)
begin
  exec ('insert into tb'+cast(@i as varchar(10))+'insert into tb2
select * from #t
where id between '+cast(@i*100+5 as varchar(10))+' and '+cast(@i*100 as varchar(10)))
set @i=@i+1
end

自己测试

#3


好的,谢谢了。

#1


如果建了聚集索引,是可以的,价格具有顺序的id列,然后再获取你那些范围再插入。

#2


select id=identity(int,1,1) into #t from tb 
insert into tb2
select * from #t
where id between 5 and 100

如果你要编程实现的话,需要使用循环,并且要插入数据的表名是有规律的

declare @i int 
set @i=0
while (条件自己写)
begin
  exec ('insert into tb'+cast(@i as varchar(10))+'insert into tb2
select * from #t
where id between '+cast(@i*100+5 as varchar(10))+' and '+cast(@i*100 as varchar(10)))
set @i=@i+1
end

自己测试

#3


好的,谢谢了。