You are on page 1of 3

Querying across 2 different databases is a distributed query.

For distributed queries you need to create linked servers. Then


provide the fully qualified path to the resource you are
querying. For example:

select * from [Server-Name].[DB-Name].[dbo].[Table-Name]

And a distributed query with 2 servers:

SELECT * FROM [Db1].[dbo].table1 A INNER JOIN


[Server2].[Db1].[dbo].table2 B ON A.Id = B.Id

I found this on making a linked server. I have not tried this


myself!

How to Add SQL Server Linked Server on SQL Server 2012

1.) Connect to SQL Server 2012 database instance using SQL


Server Management Studio (SSMS) with a SQL login that
has sysadmin server role.

Within Object Explorer window, drill-down from SQL Server


instance node to Server Objects > Linked Servers node.

Right click on the Linked Servers node, and choose New Linked
Server... from context menu.

2.) Then the create New Linked Server wizard screen is displayed
as seen in below screenshot.On the wizard screen, you can add
linked server using two methods according to the target server
type. These two options are one for SQL Server server type and
one for Other data source server types.

If the target server for new linked server is SQL Server, then
choose server type as "SQL Server". The only configuration
parameter on this screen is the name of the SQL Server instance.
You can provide SQL Server instance name in the "Linked Server"
textbox.Then other input areas will turn into grey, non-editable
input textboxes.
If the SQL Server is default instance then it is enough only to
enter the server name. But if the SQL Server instance is a named
instance then you can define the linked server name in
"[servername\instancename]" syntax.
3.) Switch to Security page (or tab) in order to define security
context.After target SQL Server instance is defined, next step
is providing the security context (username password
information) used when executing sql commands over the SQL
Server linked server.

In security page, you can map local SQL Server login to remote
server login. And the bottom section of the security tab, you
can define default security context for connections over linked
server. You have the following options:Not be made,Be made
without using a security context,Be made using the login's
current security context,Be made using this security context:
(Here you should provide remote login name and password)
After security context is also completed, press OK button to
create linked server on SQK Server 2012.

You might also like