Solved

Link tables in SQL Server

Posted on 2004-10-20
5
207 Views
Last Modified: 2006-11-17
Ok, easy question.

How do you link tables in SQL Server?  That is, how do you access tables from other databases (on the same SQL Server)?
0
Comment
Question by:tristan256
  • 3
5 Comments
 
LVL 34

Accepted Solution

by:
arbert earned 210 total points
ID: 12366645
If you want to access tables ON THE SAME SERVER in another database, just use the naming convention:

select * from databasename.owner.tablename

Of course, you need permissions in the other database....
0
 
LVL 34

Expert Comment

by:arbert
ID: 12366653
And if you wanted to join from the current database to tables in another database:

select * from currentdbtable t1 inner join otherdatabase.owner.tablename t2
on t1.key=t2.key
0
 

Author Comment

by:tristan256
ID: 12366726
aah, didn't know you had to specify the owner as well.

Cheers.
0
 
LVL 34

Expert Comment

by:arbert
ID: 12366832
Good deal.  Always a good habit to get into to always include the owner...
0
 

Expert Comment

by:bhavik
ID: 12411317
What do I have to do,  so that the table in database A is available to all databases (B, C,...) In a way that any queries done by connecting to n B and C looks like the table is in B and C.
I do not want to use the fully qualified name nor do I want to change my code to add openquery statements.

The situation is I'm using dotnet code to query two databases that where split out of one.









0

Featured Post

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I wrote this interesting script that really help me find jobs or procedures when working in a huge environment. I could I have written it as a Procedure but then I would have to have it on each machine or have a link to a server-related search that …
When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question