Access tables from different databases in SQL Server

Saturday, April 5, 2008



This article will explain how can you join tables from different databases.

Suppose you have a table Table1 in Database DB1 and other table Table2 in DB2 on the same servers and currently you are using Database DB1 then to access the Table2 you can simply prefix it with DB2..

Note the two dots after the Database name.

For example,

SELECT * FROM TABLE1 JOIN DB2..TABLE2
ON TABLE1.KEY = DB2..TABLE2.KEY

0 comments:

Post a Comment

Followers

 

2009 ·Techy Freak by TNB