title: More Efficient Way to Copy Large Data from One Table to Another
body: <p>We have a few tables with over 300,000 records and it takes several hours for records to be transferred/copied from one table to another table.  Is there a more efficient effective way than using cursors and copying each record one by one from one table to another table, when dealing with large quantities of data?</p>
  
  <p>Code:</p>
  
  <pre><code>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&gt;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 
  </code></pre>