sql-serverdatabaseviewcross-database

Join multiple databases in one View -- SQL Server Mangement Studio


I would like to join fields from two different databases that reside on the same server, but I am having trouble with the syntax.

Can anyone provide some insight?


Solution

  • Assuming that your user has privileges in both databases, just reference the "remote" object using three part naming:

    SELECT columns
    FROM database2.dbo.table