473,320 Members | 1,978 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

How to join tables in different databases

Guys, heres my problem.

I'm developing a CRM system for the place i work and in that MS SQL Server database i have an Employees table. Now the thing is this table can and will be used for new systems which will be built in the future. So i think it is appropriate to have it in a seperate database rather than creating an Employees table in each and every database used for those systems.
Thats when the problem arises. Having the employees table in a different database prevents me from JOINING its data with other tables in other databases using queries in the normal way. Is there a way to overcome this? Or am i going about it in a wrong way? Thanks in advance for ur help.
Apr 10 '07 #1
7 60058
iburyak
1,017 Expert 512MB
If it is on the same Server just prefix table name with database name and owner.

Assume you have Database1 and Database2. Table Employees is in Database1


From Database2 do following:


[PHP]Select * from Database1.dbo.Employees[/PHP]

The same thing you use in joins.

Hope it helps.
Apr 10 '07 #2
Thanks man. Guess i can refer to that table by [DatabaseName].[Owner].[TableName] in a join after all. But i also came to know that u can do that only if the two databases reside in the same SQL server. If not i may have to implement link-servers (or whatever hmm....). How exactly in MS SQL Server 2005 do u do that? Please explain...
Apr 10 '07 #3
iburyak
1,017 Expert 512MB
I thought databases are on the same server.
To link a server, follow this example from help. It should be done once.

[PHP]A. Use the Microsoft OLE DB Provider for SQL Server
Creating a linked server using OLE DB for SQL Server
This example creates a linked server named SEATTLESales that uses the Microsoft OLE DB Provider for SQL Server.

USE master
GO
EXEC sp_addlinkedserver
'SEATTLESales',
N'SQL Server'
GO[/PHP]


After servers are linked you can reference table on another server like:

[Server name].[database name].[owner].table_name


There are other ways to reference table on another without actually linking servers. But if your business doesn't have objections for linking it is an easiest approach.

Good Luck.
Apr 10 '07 #4
harindaka
Guess i can refer to that table by [DatabaseName].[Owner].[TableName] in a join after all.
Thank you for rephrasing the answer that iburyak posted. It made it very easy for a newbie like me to understand. The Brackets is what helped when my database name had a space in it. You both were very helpful.
May 21 '07 #5
This topic was very much useful for me also... thanks...
Aug 5 '08 #6
Thanks, I have been looking for the solution for a while too.
Sep 1 '08 #7
jamsoi
1
any idea to make it happens in query designer 2005 ?
Oct 18 '08 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: djc | last post by:
I need to use data from multiple tables that are located in 2 different databases. Most of the tables are in SQL Server 2000 but 1 one the tables I need to include in my query resides in an...
0
by: Peter Paskoff | last post by:
at first - can´t change the server version, so i have to live with the limitations of the version. since there is no ability to create queries between different databases in this version - how...
1
by: UgoWeb | last post by:
Is it possible to execute a query between tables on different databases? thanx in advance
7
by: steve | last post by:
Can you join two tables across different servers in mySQL, or am I dreaming of Oracle? -- Posted using the http://www.dbforumz.com interface, at author's request Articles individually checked...
9
by: Fish Womper | last post by:
I am at best a part time developer of Access databases. I use Access 2.0, as this is all my employer has on its computers. Even so, to use this ancient version requires a fairly convoluted...
2
by: clickon | last post by:
DataSet relationships seem to be focussed on one to many type realtionships. I have got a one to one realtionship in a DataSet between two tables. I can't do a join between the two tables in the...
40
by: rdemyan via AccessMonster.com | last post by:
I have two databases, db1 and db2, with the same table, TableA. I want to select the records from TableA in db1 that have a LAST_UPDATE SomeDate. Then I want to get the identical records in TableA...
0
by: harindaka | last post by:
Guys, heres my problem. I'm developing a CRM system for the place i work and in that MS SQL Server database i have an Employees table. Now the thing is this table can and will be used for new...
2
by: =?Utf-8?B?VGVycnk=?= | last post by:
Is it possible to join tables from different databases? If so, what is the format of the select statement? Both databases are on the same server. TIA, -- Terry
6
by: BD | last post by:
Hi, all. I need to enforce a one-to-many relationship on 2 tables, with a join table. Say the join table contains account information. It has cust_no and acct_no. Both cust_no and acct_no are...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.