Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Optimizing loads from linked server Expand / Collapse
Author
Message
Posted Friday, October 18, 2013 3:37 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Tuesday, July 1, 2014 10:48 AM
Points: 35, Visits: 323
Hi, so I'm new to SQL Server and I recently started at a new job. We currently have about 50 jobs that run throughout the night that pull from a linked server and insert into our data warehouse.

Most of the jobs take a few minutes, but there are some that take several hours. The jobs are set up through SQL Agent as T-SQL jobs. We truncate the tables in our data warehouse daily and then load the records. Is there a more efficient way to do these loads in SSIS or a way to only load the changes that occur from the previous day?

Here's an example:
insert into dbo.claimdetail fields
select fields
from LinkedServer.prod1.dbo.clmdet
where exists (select * from LinkedServer.prod1.dbo.ClaimsToPull
where CN = cdclno and
WN = cdwkno)

Post #1506337
Posted Friday, October 18, 2013 11:40 PM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Monday, August 25, 2014 4:47 PM
Points: 192, Visits: 400
I'd recommend using SSIS as its purpose is for developing ETL processes. If you want to stay within I would use a pass through approach via open query vs a distributed query like you're using. Meaning, send your statement to be executed on the remote server and have it pull the results back. Make sure that the remote server has proper indexing for the statement it's running.


insert into dbo.claimdetail fields
select fields
from LinkedServer.prod1.dbo.clmdet
where exists (select * from LinkedServer.prod1.dbo.ClaimsToPull
where CN = cdclno and
WN = cdwkno)

to

INSERT INTO claimdetail (col1,col2,...)
SELECT col1, col2, ....
FROM OPENQUERY (LinkedServer, 'SELECT col1, col2, ... FROM clmdet c WHERE EXISTS ( SELECT 1 FROM prod1.dbo.ClaimsToPull p WHERE c.Col = p.Col AND CN = CdClNo AND WN = CdWkNo')

Here is a great article from a MSDN blog:

http://blogs.msdn.com/b/sqlsakthi/archive/2011/05/09/best-performer-distributed-query-four-part-or-openquery-when-executing-linked-server-queries-in-sql-server.aspx
Post #1506364
Posted Saturday, October 19, 2013 12:29 AM


SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Tuesday, March 25, 2014 7:22 AM
Points: 77, Visits: 150
Hi hogpen, and welcome to the forum

Good thing would be also to drop non clustered indexes on your claimdetail table before ETL and recreates them after.

Hope it helps.


Jonathan Bernardez Bernardez
___________________________________________________________
DBD. MCSA SQL Server 2012
Post #1506369
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse