Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Slow Insert to LinkedServer

Posted on 2006-10-23
6
Medium Priority
?
1,284 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

 

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 143

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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
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…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.

718 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