473,772 Members | 3,672 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

PK--> FK relationship between tables of different databases

Hi there,

Is it possible to have a primary key - foreign key relationship between
tables in different databases in DB2 ? (databases are installed in
different physical servers)

Thanks a lot for your answers

Dov MORYUSEF
Nov 12 '05 #1
3 4091
This can be done trough federated server. However created constraint
cannot be ENFORCED. To use this feature, you have to enable Federated
Database System Support on both servers by issuing statement in Command
Window:
db2 update dbm cfg using FEDERATED YES
Next steps: create wrapper, server, nickname and at last create foreign
key which references created nickname.

--First server
CONNECT TO db_one user akalicki using ****;
CREATE TABLE akalicki.Test1 (col1 INT, col2 INT);
DISCONNECT db_one;
--Second server
CONNECT TO db_two user db_user using ****;

CREATE WRAPPER DRDA LIBRARY 'db2drda.dll' OPTIONS( ADD DB2_FENCED 'N');

CREATE SERVER DB_ONE TYPE DB2/UDB VERSION '8.2' WRAPPER DRDA AUTHID
"akalicki" PASSWORD "*****" OPTIONS( ADD DBNAME 'DB_ONE', PASSWORD
'Y');

CREATE USER MAPPING FOR "DB_USER" SERVER "DB_ONE" OPTIONS ( ADD
REMOTE_AUTHID 'akalicki', ADD REMOTE_PASSWORD '*****') ;

CREATE NICKNAME db_user.Test_ni ckname FOR DB_ONE.akalicki .Test1;

CREATE TABLE db_user.Test2 (col1 INT, col2 INT);

ALTER TABLE db_user.Test2
ADD CONSTRAINT CONST_FK FOREIGN KEY (col2)
REFERENCES db_user.Test_ni ckname (col1)
ON DELETE NO ACTION ON UPDATE NO ACTION
NOT ENFORCED ENABLE QUERY OPTIMIZATION ;

CONNECT RESSET;

Nov 12 '05 #2
Thanks for your answer.

In fact, my first server is DB2 UDB for iSeries V5R3 and second a DB2
UDB V8 for Linux. I have to adapt your commands to these platforms.

I will try it.

Many thanks.

Dov
ad****@wp.pl a écrit :
This can be done trough federated server. However created constraint
cannot be ENFORCED. To use this feature, you have to enable Federated
Database System Support on both servers by issuing statement in Command
Window:
db2 update dbm cfg using FEDERATED YES
Next steps: create wrapper, server, nickname and at last create foreign
key which references created nickname.

--First server
CONNECT TO db_one user akalicki using ****;
CREATE TABLE akalicki.Test1 (col1 INT, col2 INT);
DISCONNECT db_one;
--Second server
CONNECT TO db_two user db_user using ****;

CREATE WRAPPER DRDA LIBRARY 'db2drda.dll' OPTIONS( ADD DB2_FENCED 'N');

CREATE SERVER DB_ONE TYPE DB2/UDB VERSION '8.2' WRAPPER DRDA AUTHID
"akalicki" PASSWORD "*****" OPTIONS( ADD DBNAME 'DB_ONE', PASSWORD
'Y');

CREATE USER MAPPING FOR "DB_USER" SERVER "DB_ONE" OPTIONS ( ADD
REMOTE_AUTHID 'akalicki', ADD REMOTE_PASSWORD '*****') ;

CREATE NICKNAME db_user.Test_ni ckname FOR DB_ONE.akalicki .Test1;

CREATE TABLE db_user.Test2 (col1 INT, col2 INT);

ALTER TABLE db_user.Test2
ADD CONSTRAINT CONST_FK FOREIGN KEY (col2)
REFERENCES db_user.Test_ni ckname (col1)
ON DELETE NO ACTION ON UPDATE NO ACTION
NOT ENFORCED ENABLE QUERY OPTIMIZATION ;

CONNECT RESSET;

Nov 12 '05 #3
If you'd like it to be enforced, perhaps you could CREATE the TABLE
locally and keep it in sync with the other database via a job (such as
every hour, day, or week).

B.

Nov 12 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1785
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?
3
23231
by: Henri | last post by:
Hello, I am quite new to ms-sql and I have a problem : I want to create an SQL request which would copy serveral records from a table in a given database to another table (with exactly the same structure) in another database (theses two tables and databases already exist). Could you please tell me how to do this ? I dont know how to access two different databases in a single SQL request.
2
7354
by: Kenneth Fosse | last post by:
Hi. I'm currently working on a project which involves the creation of a web page which reports selected data to customers from two back-end systems. I use ASP script language on IIS, the server is MS SQL 2000. Now I'm struggling with combining two tables from the different databases. I'm sure it's simple enough, but I'm a little short on the SQL expertise. I've got two databases, db1 and db2, and then two tables, db1.t1 and
10
25546
by: Captain Nemo | last post by:
Hi I'm working on an ASP project where the clients want to be able to effectively perform SELECT queries joining tables from two different databases (located on the same SQL-Server). Does this involve creating virtual tables that link to another database, or am I completely on the wrong track? Any hints as to where I might find more information (buzz-words, etc.) would
2
2618
by: cspowart | last post by:
Consider first, table "A" : Plate Make Model ===================== ABC123 Ford F150 XYZ789 Dodge 1500 IJK444 Chev Silverado Then consider, table "B";
2
2963
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
18
50759
by: asi242 | last post by:
Hello, Good day to all... I just want to ask.. How would you connect two tables from 2 different databases using PHP scripts? Because, one database that contains customer table is dedicated to one project, and then here comes another project that also uses the customer table...the clients dont want to reenter all of values from the first database to the second database. Dumping would not be an option cause they want the two projects to run...
3
1425
by: Aswanth | last post by:
Hi.., I'm having Two Stored Procedures in Two Different Databases.. Database1 - Employee Stored Procedure - Employee_Details Database2 - Company Stored Procedure - Company_Details
4
4101
by: sganeshsvk | last post by:
sir, i want to store the same data values in two different databases at that same time in mysql using php programming. suppose any one databases data will lose then we use the other databases. suppose there is any query for store the same data values in two different databases at the same time. for eg: databases sample1
0
10261
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10104
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8934
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...
1
7460
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6715
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5354
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
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4007
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
2
3609
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.