Link to home
Start Free TrialLog in
Avatar of mohanrao
mohanrao

asked on

Query tables in another database

Hi,
   i have connected to database X. from this connection i would like to access tables in another database. purpose is to join tables in different database.

Regards,
Rao.
Avatar of Maciej Pilecki
Maciej Pilecki
Flag of Poland image

If the databases are on the same server you can just use the syntax:
dbname.owner.table
to query the table residing in another db.

If the database are on the separate servers, you have to set up one server as linked server on the other (this can but does not have to be bi-directional link), and then use the syntax:
servername.dbname.owner.table

Avatar of mohanrao
mohanrao

ASKER

yes, it is two different servers. how can i do this "Linked server setup"
ASKER CERTIFIED SOLUTION
Avatar of Maciej Pilecki
Maciej Pilecki
Flag of Poland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Go to enterprise manager

under security - you will see linked servers

right click on linked server
click on ne linked server
dialog box will open up
in linked server - type the name of the server you want to link
click on security tab
click radio button - they will be mapped to

this is for the remote server
remote user - username
password

at the bottom

login name - enter login name - example sa
remote user - enter username - example sa
when it has successfully created a link
you will see the name of the server
under that you will see tables - nothing else

when you need to query the database from query
analyzer

servername.databasename.dbo.tablename