Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can you create a link between tables 1

Status
Not open for further replies.

danjapro

Programmer
Aug 27, 2004
54
US
How can you create a link between tables in different databases.

What method can I use to create this link between tables in sql server databases.

Example:

Database 1 table user Database 2 table userinfo
 
Assuming that there is a field UserId in common between your two tables user and userinfo, then try

Code:
select *
from user u
inner join userinfo ui on u.userid = ui.userid
 
A fully qualified table name is in this form:
ServerName.DatabaseName.TableOwner.TableName
You can start from the right as use as much as you need to. If you need to specify a ServerName then you will need to link the remote server to your local server with sp_addlinkedserver before you can use that syntax.
-Karl

[red] Cursors, triggers, user-defined functions and dynamic SQL are an axis of evil![/red]
[green]Life's uncertain...eat dessert first...www.deerfieldbakery.com[/green]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top