?
Solved

How to run cross server , cross database query

Posted on 2004-10-11
4
Medium Priority
?
516 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
4 Comments
 
LVL 12

Accepted Solution

by:
catchmeifuwant earned 100 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
In today's business world, data is more important than ever for informing marketing campaigns. Accessing and using data, however, may not come naturally to some creative marketing professionals. Here are four tips for adapting to wield data for insi…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

850 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