SQL serve querying data methods across servers

Source: Internet
Author: User
Tags knowledge base


Today in SQL Server data query, you need to use a cross-server connection , here to record how to use the cross-server query method in SQL Server, there are the following steps.

/*
Create an intermediate database link
exec sp_addlinkedserver ' middledata ', ' ', ' SQLOLEDB ', ' database connection instance, or IP '
exec sp_addlinkedsrvlogin ' Middledata ', ' false ', NULL, ' Database connection account ', ' Database connection password '
*/

Once you have created a connection, you can query the data from the remote database in the query window of the current database

Select Top Ten * from Middledata. Database name. dbo. database table name

The format is as follows: Select Top * from MIDDLEDATA.DATABASETEST.DBO.LC_GCSG_HTCB


If you do not need this database connection, you can delete it, delete the following method:
/*
Delete
exec sp_dropserver ' middledata ', ' droplogins '
*/

Guangzhou Jing-an Technology Co., Ltd., SharePoint Professional Development, information portal, SharePoint workflow, Knowledge Base, document management and other solutions providers.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

SQL serve querying data methods across servers

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.