格林威治标准时间下午+8
有没有办法从多个数据库中搜索数据?嗯,我知道我们可以做到 如下所示:
select * from table1 where [name] = 'John'
select * from table2 where [name] = 'John'
有没有办法像
一样搜索它 select * from sometables where [name] = 'john'
答案 0 :(得分:0)
试试这个......
SELECT * FROM [DataBaseName].[Schema].[Table] WHERE [Your Condition]
您也可以在加入中使用此类查询,例如,您有两个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
答案 1 :(得分:0)
您必须设置链接服务器http://msdn.microsoft.com/en-us/library/aa560998.aspx 之后,您将能够在其他服务器上调用数据库
选择 * 从 LocalTable, [OtherServerName] [OTHERDB]。[DBO]。[OtherTable]