在两个不同的实例中联接两个表 [英] Join two tables in two difference instances

查看:74
本文介绍了在两个不同的实例中联接两个表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我在两个不同的实例中有两个ms sql表.我想加入那两个表并得到结果.可能吗.

例如
数据库1,数据库2

数据库1在实例1(sql Server 1)中
数据库2位于实例2(SQL Server 2)中


谢谢,

Hi,
I have two ms sql table in two different instances. I want to join that two tables and get the result. Is it possible.

For example
Databse 1, Databse 2

Database 1 is in instance 1(sql Server 1)
Databse 2 is in instance 2 (sql server 2)


Thanks,

推荐答案

您应使用所用对象的完全限定名称.
试试这个:
You should use a fully qualified name of the objects you are using.
Try this:
SELECT E.ID, E.Name, E.Address, C.Code, C.Mobile FROM Database1.DBO.tbEmployee E INNER JOIN Database2.DBO.tbEmployeeDtls C ON E.ID = C.ID



请参考以下链接:
http://forums.asp.net/t/1254974.aspx/1 [ ^ ]
http://stackoverflow.com/Questions/5145637/querying-data-by-joining-two-tables-in-two-database-on-different-servers [



Refer the links below:
http://forums.asp.net/t/1254974.aspx/1[^]
http://stackoverflow.com/questions/5145637/querying-data-by-joining-two-tables-in-two-database-on-different-servers[^]


--Amit


1)链接的服务器可以用于连接目的..
2)从[LocalTablename]中选择*作为不存在的t1(SELECT *从[Linkedservername] .IAT.dbo.destinationtable作为t2,其中t1.Id = t2.Id)
以上用于comapare本地表和目标表.

3)从[Linkedserver] .IAT.dbo.destinationtable中选择*,用于查看其他实例数据的数据.
4)复制到临时表中.
然后,您可以对其进行任何操作.
1)Linked server can used for connection purpose..
2)select * from [LocalTablename] as t1 where not exists (SELECT * FROM [Linkedservername].IAT.dbo.destinationtable as t2 where t1.Id=t2.Id)
above use for comapare local table and destination table.

3)select * from [Linkedserver].IAT.dbo.destinationtable it is use for see data for another instance data.
4)copy into temporary table .
Then you can do any operation on it.


这篇关于在两个不同的实例中联接两个表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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