0

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'

Mr.J
  • 430
  • 2
  • 10
  • 30
  • After seeing example I think your questing is searching data from multiple tables.if so I would prefer using join. – dev Nov 26 '13 at 07:10
  • http://stackoverflow.com/questions/436351/how-do-i-find-a-value-anywhere-in-a-sql-server-database – Gopesh Sharma Nov 26 '13 at 07:22

2 Answers2

0

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
Shahid Iqbal
  • 2,095
  • 8
  • 31
  • 51
0

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]