Query tables in another database

Posted on 2005-04-20
Last Modified: 2010-03-19
   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.

Question by:mohanrao
    LVL 6

    Expert Comment

    If the databases are on the same server you can just use the syntax:
    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:


    Author Comment

    yes, it is two different servers. how can i do this "Linked server setup"
    LVL 6

    Accepted Solution

    Best way is to use the Enterprise Manager. Linked servers are in Security branch. If your other server is SQL Server as well, it is fairly easy to set up it as linked server.
    LVL 8

    Expert Comment

    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

    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



    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    In this article—a derivative of my blog post (—I will explore a few different perspectives on which week today's date falls within using Microsoft SQL Server. First, to frame this stu…
    Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
    Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
    Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now