Solved

Slow Insert to LinkedServer

Posted on 2006-10-23
6
1,278 Views
Last Modified: 2012-05-05
Insert statement to remote server is running very slowly. I have run Profiler and find there is a 'sp_cursor' call for each row. The source system is SQL2005 and destination is SQL2000(sp4). The linked server is using 'SQL server' type connection. Source query is against a single table with a where clause. source and destination table are identical with Primary keys. Purpose is just to move the rows. Connection is a slow network connection - should be ok. I have already overcome same problem for related update and delete queries by use of 'EXECUTE (query) AT LinkedServer' that works great - but insert can not take advantage of this...

INSERT [LinkedServSQL2000sp4].dbname.schema.tablename
({column list})
Select
      {column list}
from tablename
WHERE col1 =  '7/20/2006'
  AND col2 in (2,5,7,12,32,54,45,33)

Any thoughts?
0
Comment
Question by:mvanral
  • 3
  • 2
6 Comments
 
LVL 15

Expert Comment

by:DanielSKim
ID: 17792398
is this any faster for you?

INSERT OPENQUERY([LinkedServSQL2000sp4], 'SELECT {column list} FROM dbname.schema.tablename')
Select
     {column list}
from tablename
WHERE col1 =  '7/20/2006'
  AND col2 in (2,5,7,12,32,54,45,33)
0
 
LVL 15

Expert Comment

by:DanielSKim
ID: 17792423
or

INSERT OPENQUERY([LinkedServSQL2000sp4], 'SELECT {column list} FROM dbname.schema.tablename WHERE 1 = 0')
Select
     {column list}
from tablename
WHERE col1 =  '7/20/2006'
  AND col2 in (2,5,7,12,32,54,45,33)
0
 

Author Comment

by:mvanral
ID: 17792536
I have tried both of your suggestions and both physically run - cool. BUT both still create the sp_cursor for each row. I am expecting it to do an insert statement from 1 server to the other for all the rows without the need for it to create and use a server based "Cursor" [note: I am not explicitly creating  a cursor!] and then do each row 1 at a time. I have, in test limited my row count to 50 to make sure that size is not the issue.
0
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 

Author Comment

by:mvanral
ID: 17800101
Well I have found the answer:
It is not possible to have INSERT to another server and do it FAST(i.e as a single INSERT statement). It is necessary to do 'EXECUTE (@cmdstr) AT Linked server' where the whole insert statement is passed and used to Pull the data from the source server!!! Now if you are pulling the data from a linked server all is just fine...
Took 2 days of trying everything....

I think i should get the points????
0
 

Author Comment

by:mvanral
ID: 17800129
By the way - getting it right has a radical effect on performace  - 17000 about 16 mins(975 secs) with straight INSERT statement inserting to remote server. But when instart statement put inside an EXECUTE and passed to remote server that then gets the data and inserts it locally it takes <30secs. [All other variables same!]
0
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 0 total points
ID: 17801102
Question PAQed with points refunded
good to know, btw

angelIII, page editor
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now