Can we use Multiple tables from Multiple databases in a same query?

Yes. We can do it by writing fully qualified names.

The full name of a table is made up of

  • Server name
  • Database name
  • Schema name
  • Table name

The full name of a table: Server name.Database name.Schema name.Table name

This is known as Fully qualified name or Four part naming convention.

USE MyDB

GO

SELECT * FROM MyServer.YourDB.dbo.Employee

The above SELECT statement can fetch the data from Employee table of YourDB in MyServer Server even though it is not a part of MyDB.

Happy Reading  :-) 

Leave a Reply

Your email address will not be published. Required fields are marked *