Join tables from different databases?

  • Thread starter Thread starter Guest
  • Start date Start date
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,
 
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
 
Back
Top