Solved

Slow Insert to LinkedServer

Posted on 2006-10-23
6
1,277 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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

747 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

13 Experts available now in Live!

Get 1:1 Help Now