如何从SQL Server 2005中其他服务器中的表中获取值? [英] How to get a value from a table in different server in SQL Server 2005?

查看:71
本文介绍了如何从SQL Server 2005中其他服务器中的表中获取值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我想执行一个查询,其中值之一来自另一台服务器中的一列.我的查询正在服务器中执行,并且要从其他服务器中的表中获取值之一.有人可以建议我这样做的方法吗?

在此先感谢您.

Hi All,
I want to do a query in which one of the value is from a column which is in a different server. My query is executing in a server and one of the values to be fetched from a table in a different server.Can anyone suggest me some way to do this?

Thanks in advance.

推荐答案

您的查询可以通过以下步骤实现:


1.通过SQL Server添加链接服务器.


Your query can be achieve using following steps


1.add link server thro sql server.


sp_addlinkedserver '<Server Alias>', '', 'SQLNCLI', NULL, NULL, 'SERVER=<IP>', NULL
sp_addlinkedsrvlogin '<Server Alias>', 'false', NULL, '<username>', '<password>'




只需写语句

从[LINKSERVERALIASNAME]中选择*.[DATABASENAME].[ObjectName].[TABLENAME]




just write the statement

select * from [LINKSERVERALIASNAME].[DATABASENAME].[ObjectName].[TABLENAME]


如果它是完全不同的服务器,我不确定是否可以.如果它是同一服务器上的其他数据库,则可以在SQL中引用它. SQL Server 2008及更高版本可以运行.NET代码,这可能使之成为可能.
If it''s a completely different server, I''m not sure it''s possible. If it''s a different DB on the same server, you can refer to it in your SQL. SQL Server 2008 onwards can run .NET code, which may make it possible.


好吧,您可以看看OPENROWSET

我给你一个简单的例子,以便从其他服务器中获取记录,例如

Well you can take a look at OPENROWSET

I give you a simple example to fetch records from other server like

SELECT a.* FROM OPENROWSET('MSDASQL.1', 'DRIVER=SQL Server;SERVER=192.168.2.2;UID=sa;PWD=;DATABASE=CBOS',
'SELECT * FROM MASTER') as a



尝试使用google以获得更多示例



Try google for more example


这篇关于如何从SQL Server 2005中其他服务器中的表中获取值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆