Link tables in SQL Server

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)?
tristan256Asked:
Who is Participating?
 
arbertCommented:
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
 
arbertCommented:
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
 
tristan256Author Commented:
aah, didn't know you had to specify the owner as well.

Cheers.
0
 
arbertCommented:
Good deal.  Always a good habit to get into to always include the owner...
0
 
bhavikCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.