Solved

How to run cross server , cross database query

Posted on 2004-10-11
4
502 Views
Last Modified: 2011-10-03
i have 2 physical servers and 1 database in each server, how do link all the database so that i can run the query to SELECT/INSERT data on database in each physical server?
0
Comment
Question by:jkbgk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 12

Accepted Solution

by:
catchmeifuwant earned 50 total points
ID: 12274634
Which database are you using?If using Oracle then you can use Oracle DB Links for the purpose.

Let us assume DB1 is in Server1 & DB2 is in Server2.You want to connect to DB2/Server2 from DB1/Server1.

1)From the Server1 you create tnsnames to DB2 databases.Use Oracle Net Config utility to create this entry,specifying DB SID and the Server Name or IP and a name for the connection (Let's name this connection "conn_db2")

2)Create a Database link from DB1 to DB2, using the Tnsnames that you created earlier.

CREATE DATABASE LINK link_to_db2
   CONNECT TO <username> IDENTIFIED BY <password>
   USING 'conn_db2';

3)Now using the DB Link you created, you can access the objects on DB2(provided you have the appropriate privileges like select/insert/update etc)..

--- This selects data from mytable in DB2
select * from mytable@link_to_db2;

--- Similarly you can insert ,update delete
insert into mytable@link_to_db2(col1,col2)
values(1,2);

delete mytable@link_to_db2
where col1=1;

----------------
If you don't want to explicitly specify the link name everytime you write a query, create a synonym.

create public synonym mytable_sy for mytable@link_to_db2;

Now you can treat mytable as if it's in your local database.

select * from mytable_sy;
delete mytable_sy;

0
 
LVL 2

Expert Comment

by:praveen_ms
ID: 12275582
If it is MS SQL you need to create a linked server and you can use servername.dbname.objectowner.object

Cheers
Praveen
0
 
LVL 1

Expert Comment

by:seanmrmd
ID: 12280170
Create two ODBC Connections one connecting to each database.
Then, create a new access database and LINK the tables through Access.  You will be able to perform queries as normal.  The performance won't be great, but it will get the job done.
0
 

Author Comment

by:jkbgk
ID: 12284724
should i have admin right first before i do the connection?
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question