Join tables from different databases?

G

Guest

Is it possible to join tables from different databases? If so, what is the
format of the select statement? Both databases are on the same server.
TIA,
 
M

Mark S. Milley, MCSD (BinarySwitch)

Hi Terry -

The format is this:

[databasename].[object owner name (usally dbo)].[tablename]

use database1
select * from database2.dbo.mytable

Two things to note:

Cross-database queries (especially if you're combining results or
doing cross-database joins) are S L O W, especially on tables with a
massive amount of data. You may want to revisit your approach.

Make sure that whatever user you're connecting to the database as has
access to both databases.

Happy Coding,

-Mark
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top