Two ways SQL Server queries across servers

Source: Internet
Author: User

Searching the Internet for cross-server queries, presumably linked server (pre-storage connection mode and ensure connectivity) and OpenDataSource (written in the statement, the portability of strong). Depending on the function used, the performance difference is obvious ... Although very simple, but LZ was pit for a few days only to find, ashamed.

1. Linked Server

Very useful function, add the method if there is a problem can contact LZ alone, not very complex ~

Use method One:

1 Select *  from Linkedserver1.table1


But the implementation of this approach is the same as opendatasouce, that is, the other side of the server all the relevant tables of data are downloaded to local execution. In contrast, using OPENQUERY, you can put query execution on the other side of the server execution, and the content of the transfer only query results, can greatly save the transmission of consumption. Especially when you have tables that involve more than one other server!

★ Use Method Two:

Select *  from OpenQuery (LinkedServer1,'select * FROM table1 join table2')

2. OpenDataSource

Similar to the above, there is also a function that can directly return query results, OpenRowSet.

About their use can be found in the following the classmate wrote, very detailed.

Http://www.cnblogs.com/OpenCoder/archive/2010/03/18/1689321.html

Anyway, I hope every sqler need cross-server query can avoid detours. Thank you.

Two ways SQL Server queries across servers

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.