Question

Good Afternoon in GMT +8

is there a way to search for a data from multiple databases? uhm, i know that we could do something like below:

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

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

is there a way to search for it like

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

Was it helpful?

Solution

Try this...

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

You can also use such queries in Join's e.g You have two DataBases

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

Note: Both tables have same structure like (Id, Name, FatherName, Address)

Your query will be ..

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

OTHER TIPS

You have to setup Linked server http://msdn.microsoft.com/en-us/library/aa560998.aspx After then you would be able to call database on other server

select * from LocalTable, [OtherServerName].[OtherDB].[dbo].[OtherTable]

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top