请问我有一个表共10个字段共53行数据,我要将里面的第1,2,3,4,列的数据分别插入到另一个表中5000次,如果写这个sql语句啊?
------解决方案--------------------------------------------------------
for循环5000次,insert
------解决方案--------------------------------------------------------
for(int i = 0;i<100;i++)
{
for(int j=0;j<50;j++)
{
//插入
}
}
------解决方案--------------------------------------------------------
------解决方案--------------------------------------------------------
- SQL code
declare @i int=0while (@i<5000) begin insert into tb_2(c1,c2,c3,c4) select c1,c2,c3,c4 from tb_1 set @i += 1end
------解决方案--------------------------------------------------------
+1
------解决方案--------------------------------------------------------
------解决方案--------------------------------------------------------
- SQL code
declare @i int=0while (@i<5000) begin insert into tb_2(c1,c2,c3,c4) select c1,c2,c3,c4 from tb_1 set @i += 1end
------解决方案--------------------------------------------------------
------解决方案--------------------------------------------------------
------解决方案--------------------------------------------------------
------解决方案--------------------------------------------------------
你直接先查询出结果集,然后排序,然后在遍历插入啊。。。
别在执着啊。。
declare @i int=0
while (@i<5000) begin
insert into tb_2(c1,c2,c3,c4)
select c1,c2,c3,c4
from tb_1
order by ??
set @i += 1
end
------解决方案--------------------------------------------------------
插入5000次。。少侠好功夫啊。
------解决方案--------------------------------------------------------
------解决方案--------------------------------------------------------