Optimizing loads from linked server

  • 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)

  • 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

  • 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

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply