我们有几个表有超过 300,000 条记录,记录从一个表传输/复制到另一个表需要几个小时。在处理大量数据时,有没有比使用游标并将每条记录从一张表逐个复制到另一张表更有效的方法?
代码:
open SOMETBL
fetch SOMETBL into @key1,@key2,@key3,@key4
while(@@fetch_status = 0)
begin
SELECT @key1InMapping = count(*) FROM SOMEOTHERDB.dbo.tblSOMETBLping WHERE fldEServicesKey = @key1
SELECT @eServiceTypeKey = fldAServiceTypeKey FROM SOMEOTHERDB.dbo.tblAServiceType WHERE fldAServiceTypeNumber = @key4
if (@eServiceTypeKey=null or @eServiceTypeKey=0)
set @eServiceTypeKey = 50
if @key1InMapping>0
begin
update SOMEOTHERDB.dbo.tblSOMETBLping set fldAServiceTypeKey=@eServiceTypeKey where fldEServicesKey= @key1
-- print 'post='+convert(varchar,@key2) + ' :key1='+convert(varchar,@key1)+ ' :serviceTypeKey='+convert(varchar,@eServiceTypeKey)+' : serviceTypeNum='+convert(varchar,@key4)
end
fetch SOMETBL into @key1,@key2,@key3,@key4
end
close SOMETBL