KB: SQL openquery vs linked server

Good read: Openquery vs Linked Server

 

The linked server query, SQL Server is going to make decisions for you on how it mashes all the data together and returns the result set. By default, when you run a distributed query using a linked server, the query is processed locally. This may or may not be efficient, depending on how much data must be sent from the remote server to the local server for processing. Sometimes it is more efficient to pass through the query so that it is run on the remote server. This way, if the query must process many rows, it can process them on the remote server, and only return to the local server the results of the query. The OPENQUERY function is used to specify that a distributed query be processed on the remote server instead of the local server.


The alternative to using Linked Servers is to use the OPENQUERY statement, also known as a pass through query. When using an OPENQUERY statement, the WHERE clause gets executed at the remote server and the resultant (mapped) records traverse over the wire instead of an entire sourced data set. The only issue with the OPENQUERY statement is that the TSQL syntax is limited in that it does not accept variables for arguments. To get around this, you need to ensure that the OPENQUERY TSQL syntax is generically coded.


Reference:


Comments

Popular posts from this blog

KB: Azure ACA Container fails to start (no User Assigned or Delegated Managed Identity found for specified ClientId)

Electron Process Execution Failure with FSLogix

KB:RMM VS DEX (Remote Monitoring Management vs Digital Employee Experience)