Solved

How to run cross server , cross database query

Posted on 2004-10-11
4
476 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 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
This article explains all about SQL Server Piecemeal Restore with examples in step by step manner.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
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…

863 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now