dbTalk Databases Forums  

Link to table in another database

microsoft.public.sqlserver.dts microsoft.public.sqlserver.dts


Discuss Link to table in another database in the microsoft.public.sqlserver.dts forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
bill_morgan_3333
 
Posts: n/a

Default Link to table in another database - 10-17-2004 , 05:31 PM






Friends,

Our company is running two databases in one instance of SQL Server 2000
(db_1 and db_2). QUESTION: From db_1, how do I link to a table in db_2 so
that I can create a db_1 View that is a join between a table in db_1 and a
table in db_2?

For example, from an MS-Access ODBC link to our SQL Server, I can choose
File / Get External Data / Link Tables to link to the two tables - one table
in db_1 and the other table in db_2. Then I can create a query that joins the
two linked tables.

How can I accomplish this same join from within SQL Server?

Thanks for your help ...

Bill





Reply With Quote
  #2  
Old   
Jéjé
 
Posts: n/a

Default Re: Link to table in another database - 10-17-2004 , 06:01 PM






creating a view which link 2 tables from 2 differents databases is very easy
in SQL

Because the syntax of a select statement is like this:
Select * from <Servername>.<Database>.<Catalog>.<Table>

So the answer to the question is :
select * from DB1.dbo.Table1 A inner join DB2.dbo.Table2 B
on A.Key = B.Key

This join your 2 tables.
And if your second database is on another server (or another instance), you
just have to add a linked server in the security information then:
select * from DB1.dbo.Table1 A inner join SERVERB.DB2.dbo.Table2 B
on A.Key = B.Key

(This remote server can be "any" database server like SQL Server, Oracle,
Access, DB2 ....)


"bill_morgan_3333" <bill_morgan_3333 (AT) discussions (DOT) microsoft.com> a écrit dans
le message de news: 316AE5B0-0681-4CDF-8E00-7E6E885724CF...soft (DOT) com...
Quote:
Friends,

Our company is running two databases in one instance of SQL Server 2000
(db_1 and db_2). QUESTION: From db_1, how do I link to a table in db_2 so
that I can create a db_1 View that is a join between a table in db_1 and a
table in db_2?

For example, from an MS-Access ODBC link to our SQL Server, I can choose
File / Get External Data / Link Tables to link to the two tables - one
table
in db_1 and the other table in db_2. Then I can create a query that joins
the
two linked tables.

How can I accomplish this same join from within SQL Server?

Thanks for your help ...

Bill







Reply With Quote
  #3  
Old   
bill_morgan_3333
 
Posts: n/a

Default Re: Link to table in another database - 10-17-2004 , 08:53 PM



Jeje,

Thanks so much for your response. Didn't realize I could reference tables
from another database in a View. Your clear instructions were really helpful.
Thanks again...

Bill

"Jéjé" wrote:

Quote:
creating a view which link 2 tables from 2 differents databases is very easy
in SQL

Because the syntax of a select statement is like this:
Select * from <Servername>.<Database>.<Catalog>.<Table

So the answer to the question is :
select * from DB1.dbo.Table1 A inner join DB2.dbo.Table2 B
on A.Key = B.Key

This join your 2 tables.
And if your second database is on another server (or another instance), you
just have to add a linked server in the security information then:
select * from DB1.dbo.Table1 A inner join SERVERB.DB2.dbo.Table2 B
on A.Key = B.Key

(This remote server can be "any" database server like SQL Server, Oracle,
Access, DB2 ....)


"bill_morgan_3333" <bill_morgan_3333 (AT) discussions (DOT) microsoft.com> a écrit dans
le message de news: 316AE5B0-0681-4CDF-8E00-7E6E885724CF...soft (DOT) com...
Friends,

Our company is running two databases in one instance of SQL Server 2000
(db_1 and db_2). QUESTION: From db_1, how do I link to a table in db_2 so
that I can create a db_1 View that is a join between a table in db_1 and a
table in db_2?

For example, from an MS-Access ODBC link to our SQL Server, I can choose
File / Get External Data / Link Tables to link to the two tables - one
table
in db_1 and the other table in db_2. Then I can create a query that joins
the
two linked tables.

How can I accomplish this same join from within SQL Server?

Thanks for your help ...

Bill








Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.