Why is using OPENQUERY on a local server bad?

后端 未结 3 1069
不知归路
不知归路 2021-02-09 19:18

I\'m writing a script that is supposed to run around a bunch of servers and select a bunch of data out of them, including the local server. The SQL needed to SELECT the data I n

3条回答
  •  滥情空心
    2021-02-09 19:47

    Just a followup.

    OpenQuery is good when you have to compare or manipulate some rowsets from stored procedures.

    for example if you have to compare results from two servers (test and rollout server) when you migrate from SQL Server 2005 to SQL server 2008 for example, then you can do the following query:

    select * into test_table from OpenQuery(testServer, 'exec testdb.dbo.test_sp');
    select * into rollout_table from OpenQuery(rolloutServer, 'exec testdb.dbo.test_sp');
    
    select * from test_table
    except
    select * from rollout_table;
    
    select * from rollout_table
    except
    select * from test_table;
    

    to see any discrepancies.

提交回复
热议问题