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
自己测试
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
自己测试
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
好的,谢谢了。