HiveBrain v1.2.0
Get Started
← Back to all entries
snippetsqlMinor

Is it possible to create a database called C that is a view into all tables in database A + B?

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
tablescalledcreateallintoviewdatabasepossiblethat

Problem

Using SQL 2005 or 2008, is it possible to create a database called C that is a view into all tables in database A + B ? Databases A, B, and C are on the same local server.

I am wanting to be able to create join queries between tables that are in 2 different databases. Is there another way to do this?

Solution

You can create DatabaseC if you want to, but it adds no value. Just use 3 part object names:

SELECT 
   A.col1, B.col2
FROM
   DatabaseA.dbo.TableA A
   JOIN
   DatabaseB.dbo.TableB B ON A.xx = B.xx

Code Snippets

SELECT 
   A.col1, B.col2
FROM
   DatabaseA.dbo.TableA A
   JOIN
   DatabaseB.dbo.TableB B ON A.xx = B.xx

Context

StackExchange Database Administrators Q#8268, answer score: 5

Revisions (0)

No revisions yet.