Query different database SQL server

Typically linked servers are configured to enable the Database Engine to execute a Transact-SQL statement that includes tables in another instance of SQL Server, or another database product such as Oracle. Many types OLE DB data sources can be configured as linked servers, including Microsoft Access and Excel.
Linked servers offer the following advantages:
- The ability to access data from outside of SQL Server.
- The ability to issue distributed queries, updates, commands, and transactions on heterogeneous data sources across the enterprise.
- The ability to address diverse data sources similarly.
Read more about Linked Servers.
- Server Objects -> Linked Servers -> New Linked Server
- Provide Remote Server Name.
- Select Remote Server Type (SQL Server or Other).
- Select Security -> Be made using this security context and provide login and password of remote server.
- Click OK and you are done !!
Here is a simple tutorial for creating a linked server.
OR
You can add linked server using query.
Syntax:
sp_addlinkedserver [ @server= ] 'server' [, [ @srvproduct= ] 'product_name' ] [, [ @provider= ] 'provider_name' ] [, [ @datasrc= ] 'data_source' ] [, [ @location= ] 'location' ] [, [ @provstr= ] 'provider_string' ] [, [ @catalog= ] 'catalog' ]
Read more about sp_addlinkedserver.