Solved

Link tables in SQL Server

Posted on 2004-10-20
5
205 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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Join & Write a Comment

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…
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now