Solved

Slow Insert to LinkedServer

Posted on 2006-10-23
6
1,279 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
sql server insert 12 30
SQL Insert parts by customer 12 34
T-SQL: "HAVING CASE" Clause 1 27
T-SQL: New to using transactions 9 31
When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
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…
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
Via a live example, show how to shrink a transaction log file down to a reasonable size.

821 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