Home  >  Article  >  Database  >  同一个sql语句 连接两个数据库服务器

同一个sql语句 连接两个数据库服务器

WBOY
WBOYOriginal
2016-06-07 17:58:561643browse

在sqlserver查询分析器中,一个sql语句连接两个数据库服务器的一种方法

exec sp_addlinkedserver '逻辑名称','','SQLOLEDB','远程服务器名或ip地址'
exec sp_addlinkedsrvlogin '逻辑名称','false',null,'用户名','密码'
go

建立完成之后就可以正常使用了

select * from 逻辑名称。数据库名称。dbo。表名称 这是一个完整的sql语句

使用完成之后要,删除掉建立的虚拟连接

exec sp_dropserver '逻辑名称','droplogins'
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn