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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Linking tables from 2 different databases

Status
Not open for further replies.

ccampbell

Programmer
Aug 16, 2001
201
US
Hello,
I have kind of a sticky problem. I have a database that contains a majority of the data that I need for a new database, but I need to add a few extra tables to make the database complete. Here is the problem. I have the limitation that I cannot add additional tables to the existing database. I need to create a new database but I would like teh information in 2 tables in my new database to be the same as the information from 2 tables in my old database. Any ideas on how to do this? Is there a way to create just stand alone tables that link to a database but are not part of a database? Am I making any sense? Please help.
 
If you are wanting to link data in Table 1 from DB1 with data in Table 1 in DB2 then use the full DBname path in your SQL join statement. For Example: SELECT * FROM DB1..Table1 a JOIN DB2..Table1 b on a.linkingfield = b.linkingfield.
 
Will the databases be on the same server? If so, I just created a view using the table I wanted from the other database (use the fully qualified name). The beauty of this is you can then limit exactly what columns are available to the users if you need to.

For example, I needed to access some of the information from the Employee table in the Timesheet database as part of the Proposals database. I created the following view:

Use Proposals
CREATE VIEW dbo.ViewEmployees
AS
SELECT EmployeeFirstName, EmployeeMiddleName, EmployeeLastName, EmployeeJobTitle,
EmployeeDepartment
FROM TimeSheet.dbo.Employee
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top