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

Posted on

Question :

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?

Answer :

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

Leave a Reply

Your email address will not be published.