连接来自不同服务器的表
有什么建议如何在存储过程中连接来自不同服务器的表吗?
Any suggestions how to join tables from different servers in stored procedure?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
有什么建议如何在存储过程中连接来自不同服务器的表吗?
Any suggestions how to join tables from different servers in stored procedure?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(4)
如果没有更多细节,很难给出直接的例子,但基本思想如下:
首先,在存储过程之外,主机服务器(存储过程所在的服务器)必须了解第二台服务器,包括(可能是) 登录信息。
在主服务器上,运行 sp_addlinkedserver 存储过程。这只需要完成一次:
如果您需要向第二个服务器提供登录信息(例如,该进程无法使用初始数据库连接中使用的相同凭据登录) ,使用 sp_addlinkedsrvlogin 存储过程:
然后,在存储过程中,您可以指定第二个服务器上的表:
Without more details, it's hard to give direct examples, but here is the basic idea:
First, outside of the stored procedure, the host server (the server the stored procedure will be on) has to know about the second server, including (possibly) login information.
On your main server, run the sp_addlinkedserver stored procedure. This only has to be done once:
If you need to provide login information to this second server (for example, the process can't log in with the same credentials that are used in the initial database connection), do so with the sp_addlinkedsrvlogin stored proc:
Then, in your stored procedure, you can specify tables on the second server:
1. 使用
exec sp_helpserver
检查您是否有任何链接服务器2. 如果您的服务器未返回,则它不是
链接
意味着您需要添加它。 否则请转到步骤 3。对于 Sql Server 2008 R2,请转到
服务器对象 >链接服务器>添加新的链接服务器
或
3. 连接到辅助服务器,如下所示...
4. 现在您可以加入两个不同服务器的表。
1. Check to see if you have any linked servers using
exec sp_helpserver
2. If your server is not returned then it is not
Linked
meaning you will need to add it. Otherwise move to step 3.For Sql Server 2008 R2, go to
Server Object > Linked Servers > Add new Linked Server
Or
3. Connect to the Secondary server like so...
4. Now you can Join the tables for the two different servers.
在加入表之前,您必须首先链接两台服务器。一旦它们链接起来,您就可以使用下面的查询并替换服务器、数据库和数据库。表名。
请记住在 DB2 中执行以下 sql:
链接服务器 - http://msdn.microsoft .com/en-us/library/ms188279.aspx
You have to first link two servers before joining the tables. Once they are linked, you can just use the below query and replace server, database & table names.
Remember to execute the below sql in DB2:
Linking servers - http://msdn.microsoft.com/en-us/library/ms188279.aspx
您可以编写如下语法的查询来加入 SQL Server
p/s 中的其他服务器: COLLATE DATABASE_DEFAULT 进行编码,
防止出现以下错误
无法解决等于操作中“Vietnamese_CI_AS”和“SQL_Latin1_General_CP1_CI_AS”之间的排序规则冲突。
You can write query as below syntax to join other server in SQL Server
p/s: COLLATE DATABASE_DEFAULT to encode,
Prevent bellow error
Cannot resolve the collation conflict between "Vietnamese_CI_AS" and "SQL_Latin1_General_CP1_CI_AS" in the equal to operation.