Solved

How to run cross server , cross database query

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
CCModeler offers a way to enter basic information like entities, attributes and relationships and export them as yEd or erviz diagram. It also can import existing Access or SQL Server tables with relationships.
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…

757 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