Joins across two databases

  • Thread starter Thread starter Greg Smith
  • Start date Start date
G

Greg Smith

I am using SQL Server 2000 as the backend for an application in C#. Is
there a way to do a join on tables in different databases or do you have to
do some in memory slight of hand to accomplish it?

Any help is greatly appreciated.
 
Below is a useless query but shows how to join tables in two databases. I
assume the databases are on same server.


select * from bmcdemo.dbo.sysobjects b1 , bmcdemo2.dbo.sysobjects b2
where b1.name =b2.name

Lloyd Sheen
 
Thanks for LIoyd's quick response.

Hi Greg

Thank you for posting in the community!

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need to join tables in different
databases on the same server. If there is any misunderstanding, please feel
free to let me know.

Just as Lloyd says, when getting data from tables in other databases, we
just need to add the server name, database name and user account before the
table name. Here is the syntax:

ServerName.DatabaseName.UserAccount.TableName.

We can use all of them or omit some of them. For example:

select * from northwind..products

Notice that there are two dots between northwind and products. I have
omitted UserAccount.

HTH. Does this answer your question? If anything is unclear, please feel
free to reply to the post.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
Back
Top