【问题标题】:searching data from multiple database从多个数据库中搜索数据
【发布时间】:2013-11-26 07:04:31
【问题描述】:

格林威治标准时间 +8 下午好

有没有办法从多个数据库中搜索数据?嗯,我知道我们可以做到 如下所示:

select * from table1 where [name] = 'John'

select * from table2 where [name] = 'John'

有没有办法像这样搜索它

select * from sometables where [name] = 'john'

【问题讨论】:

标签: sql tsql sql-server-2000


【解决方案1】:

试试这个...

  SELECT * FROM [DataBaseName].[Schema].[Table] WHERE [Your Condition]

您也可以在 Join 中使用此类查询,例如您有两个 DataBases

DataBase1: 
DataBase Name : MyDB1
Table Name : Table1
DataBase2:
DataBase Name : MyDB2
Table Name : Table1

注意:两个表的结构相同,如(Id, Name, FatherName, Address)

您的查询将是..

SELECT      *
FROM        MyDB1.dbo.Table1 a
INNER JOIN  MyDB2.dbo.Table1 b
ON          a.Id = b.Id

【讨论】:

    【解决方案2】:

    您必须设置链接服务器http://msdn.microsoft.com/en-us/library/aa560998.aspx 之后你就可以调用其他服务器上的数据库了

    选择 * 从 本地表, [OtherServerName].[OtherDB].[dbo].[OtherTable]

    【讨论】:

      猜你喜欢
      • 2016-03-22
      • 2019-07-05
      • 1970-01-01
      • 2015-11-21
      • 2019-01-08
      • 1970-01-01
      • 1970-01-01
      • 2014-06-19
      相关资源
      最近更新 更多