SQL Server implements remote database linking

Source: Internet
Author: User

--View Current link situation:


SELECT * from Sys.servers;


--use sp_helpserver to display the available servers


Exec sp_helpserver


--Delete a link that already exists


Exec sp_droplinkedsrvlogin Server alias, Null
Exec sp_dropserver Server Aliases


--use sp_addlinkedserver to add links


EXEC sp_addlinkedserver
@server = ' 192.168.2.66 ',--the server alias being accessed (used to directly use the destination server IP, or take an individual name such as: JOY)
@srvproduct = ' ',
@provider = ' SQLOLEDB ',
@datasrc = ' 192.168.2.66 '--the server to be accessed


--Use sp_addlinkedsrvlogin to add user login links


EXEC sp_addlinkedsrvlogin
' 192.168.2.66 ',--the server alias being accessed (if the alias joy is used in the sp_addlinkedserver above, this is joy too)
' False ',
Null
' Sa ',--account number
' test123 '--Password


Use an example (Access database music on the target server to view the contents of the table test):


If the alias is the target server IP when the link is established, that is 192.168.2.66


The


SELECT * FROM [192.168.2.66]. [Music].dbo.test
If the alias is joy when establishing the link,


The


SELECT * FROM [JOY]. [Music].dbo.test





Problems you may encounter:
exec sp_dropserver ' JOY ' failed to execute,


Error message: There are still remote logins or links to the server ' JOY '.


Workaround:


exec sp_droplinkedsrvlogin ' JOY ', null


exec sp_dropserver ' JOY '

SQL Server implements remote database linking

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.