How can I use a table from a different database?

  • I have created a new database and I would like to use some tables that are stored and used in a different database. Is it possible to do that? How can I do that?

    Thank you.

  • Use the 3 part naming convention:

    <Database>.<Owner>.<Object>

    For instance:

    Northwind.dbo.Customers

    The login executing the query will have to have a mapped user in the database you are referencing and permission to access the object.

    K. Brian Kelley

    http://www.truthsolutions.com/

    Author: Start to Finish Guide to SQL Server Performance Monitoring

    http://www.netimpress.com/shop/product.asp?ProductID=NI-SQL1

    K. Brian Kelley
    @kbriankelley

  • Thank you for your answer. It worked 🙂

    Can I also show that table in diagram window and create relationships with it?

    And how can I use that querystring in an asp page?

  • Thank you for your answer. It worked 🙂

    Can I also show that table in diagram window and create relationships with it?

    And how can I use that querystring in an asp page?

  • Thank you for your answer. It worked 🙂

    Can I also show that table in diagram window and create relationships with it?

    And how can I use that querystring in an asp page?

  • Haven't tried to diagrams but my hunch is you can't. If you have a modeling tool other than Enterprise Manager quite possibly you can.

    You can't do relationships like foreign key constraints across databases, though you could do so via trigger. As far as a query, something like the following is fine:

    SELECT CustID, CompanyName

    FROM Northwind.dbo.Customers

    WHERE CustID = 'AFKLI'

    K. Brian Kelley

    http://www.truthsolutions.com/

    Author: Start to Finish Guide to SQL Server Performance Monitoring

    http://www.netimpress.com/shop/product.asp?ProductID=NI-SQL1

    K. Brian Kelley
    @kbriankelley

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply