473,609 Members | 1,868 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to join tables in different databases

5 New Member
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 60075
iburyak
1,017 Recognized Expert Top Contributor
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.E mployees[/PHP]

The same thing you use in joins.

Hope it helps.
Apr 10 '07 #2
harindaka
5 New Member
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 Recognized Expert Top Contributor
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_addlinkedser ver
'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
thedaver79
1 New Member
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
syamikm
1 New Member
This topic was very much useful for me also... thanks...
Aug 5 '08 #6
yimma216
44 New Member
Thanks, I have been looking for the solution for a while too.
Sep 1 '08 #7
jamsoi
1 New Member
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
3347
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 Access2002 mdb file. I need to do this via ASP/ADO on IIS5. How do I combine (join in a query) tables from different databases? they are each opened from a different connection object? I have only had to access tables from one source before and I...
0
1774
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 can i cover my problem described below? i guess, one part of the solution is to use pgdump, but how to continue?
1
1923
by: UgoWeb | last post by:
Is it possible to execute a query between tables on different databases? thanx in advance
7
11184
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 for conformance to usenet standards Topic URL: http://www.dbforumz.com/mySQL-Join-servers-ftopict225285.html Visit Topic URL to contact author (reg. req'd). Report abuse: http://www.dbforumz.com/eform.php?p=777346
9
2516
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 installation procedure on each PC on which it is used. I am self-taught from the help files that come with Access 2.0 and from painful experience. I've never attended any type of training course on how to develop databases in Access. I have no idea...
2
2105
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 database because the tables come from different databases (although held on the same server). However what i want is a single set of data that combines the fields like you get with an SQL join. Is there a straight forward way of doing this that i...
40
2515
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 from db2. However the LAST_UPDATE dates will be different between db1 and db2. That's the point. If they are different, then there were changes made to the record in db1. I'm going to then process this further to find out what the changes were. ...
0
1241
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 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...
2
2953
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
3789
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 child FKs to other tables (no nulls will exist in these columns). Logically, one customer can have several accounts, but one account can
0
8139
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8091
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8232
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7024
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4032
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4098
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2540
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1686
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1403
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.