473,396 Members | 2,151 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

DB2 Implementation - ERD Problems

Hi,

my team has the following problem.

There are 3 entities(A,B,C). A 'is_in' B. And A 'owns' C. (owns and
is_in are relations). C needs either A or B to be owned.
This means. Normaly C is owned by a member of A, but if this case is
not true, then C has to be owned by a member of B.
How can we realize this as a E/R diagram and in a DB2 SQL
Implementation?
We thought of making 2 Relations (r,s): A r C and B s C
But we cannot make sure that either r or s are true(existing).
Thanks a lot for your help.
Kurt Stein
Nov 12 '05 #1
4 3716
Kurt,

I see two options:
a) Use a typed table hierarchy with A under B
There are some limitatiosn of what DB2 does with typed tables.
typed tables are not exactly mainstream.
b) Extend B to truly comprise A. If A has more columns than B you can
either add it as a dimension table (also called vertical partitioning)
or you can simply add NULLable columns to B and some typeid telling you
which rows in A are also B. (thsi is how typed tables work under teh
covers).

Either way, once you have chosen one of the solutions you can declare RI
between C and B.

Cheers
Serge
--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
Nov 12 '05 #2
Kurt,

I see two options:
a) Use a typed table hierarchy with A under B
There are some limitatiosn of what DB2 does with typed tables.
typed tables are not exactly mainstream.
b) Extend B to truly comprise A. If A has more columns than B you can
either add it as a dimension table (also called vertical partitioning)
or you can simply add NULLable columns to B and some typeid telling you
which rows in A are also B. (thsi is how typed tables work under teh
covers).

Either way, once you have chosen one of the solutions you can declare RI
between C and B.

Cheers
Serge
--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
Nov 12 '05 #3
Serge Rielau wrote:
Kurt,

I see two options:
a) Use a typed table hierarchy with A under B
There are some limitatiosn of what DB2 does with typed tables.
typed tables are not exactly mainstream.
b) Extend B to truly comprise A. If A has more columns than B you can
either add it as a dimension table (also called vertical partitioning)
or you can simply add NULLable columns to B and some typeid telling you
which rows in A are also B. (thsi is how typed tables work under teh
covers).


But that would model a "is_a" relationship and not the required "is_in".

I the relationship between A and B is truly "is_in", then I don't see how
you could represent the condition that C has to be owned by either A or B
in the E/R diagram. That's just one of the restrictions of E/R.

In SQL, you can implement the 2 tables A, B, and C with C having two columns
(C1, C2), one referencing A and the other references B. Then define RI
from C1 to A and C2 to B, plus a constraint on C that says that either C1
or C2 must be NULL.

CREATE TABLE a ( a INT NOT NULL PRIMARY KEY );
CREATE TABLE b ( b INT NOT NULL PRIMARY KEY );
CREATE TABLE c (
c1 INT,
c2 INT,
FOREIGN KEY (c1) REFERENCES a,
FOREIGN KEY (c2) REFERENCES b,
CHECK ((c1 IS NOT NULL AND c2 IS NULL) OR
(c2 IS NULL AND c2 IS NOT NULL))
);

--
Knut Stolze
Information Integration
IBM Germany / University of Jena
Nov 12 '05 #4
Serge Rielau wrote:
Kurt,

I see two options:
a) Use a typed table hierarchy with A under B
There are some limitatiosn of what DB2 does with typed tables.
typed tables are not exactly mainstream.
b) Extend B to truly comprise A. If A has more columns than B you can
either add it as a dimension table (also called vertical partitioning)
or you can simply add NULLable columns to B and some typeid telling you
which rows in A are also B. (thsi is how typed tables work under teh
covers).


But that would model a "is_a" relationship and not the required "is_in".

I the relationship between A and B is truly "is_in", then I don't see how
you could represent the condition that C has to be owned by either A or B
in the E/R diagram. That's just one of the restrictions of E/R.

In SQL, you can implement the 2 tables A, B, and C with C having two columns
(C1, C2), one referencing A and the other references B. Then define RI
from C1 to A and C2 to B, plus a constraint on C that says that either C1
or C2 must be NULL.

CREATE TABLE a ( a INT NOT NULL PRIMARY KEY );
CREATE TABLE b ( b INT NOT NULL PRIMARY KEY );
CREATE TABLE c (
c1 INT,
c2 INT,
FOREIGN KEY (c1) REFERENCES a,
FOREIGN KEY (c2) REFERENCES b,
CHECK ((c1 IS NOT NULL AND c2 IS NULL) OR
(c2 IS NULL AND c2 IS NOT NULL))
);

--
Knut Stolze
Information Integration
IBM Germany / University of Jena
Nov 12 '05 #5

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

Similar topics

9
by: Anon Email | last post by:
Hi people, I'm learning about header files in C++. The following is code from Bartosz Milewski: // Code const int maxStack = 16; class IStack
24
by: Bob Alston | last post by:
Most of my Access database implementations have been fairly small in terms of data volume and number of concurrent users. So far I haven't had performance issues to worry about. <knock on wood> ...
3
by: Juerg Staub | last post by:
Hi, I have implemented IInternetProtocol and IInternetProtocolRoot in my protocol handler. Whenever I try to register the instance with IInternetSession::RegisterNameSpace, I receive a...
2
by: Fei Li | last post by:
tabpage hide() and show() do not work tabpage properties Enabled and Visible are able to be set but not work and not documented. Why?
8
by: Jef Driesen | last post by:
I'm working on an image segmentation algorithm. An essential part of the algorithm is a graph to keep track of the connectivity between regions. At the moment I have a working implementation, but...
52
by: lovecreatesbeauty | last post by:
Why the C standard committee doesn't provide a standard implementation including the C compiler and library when the language standard document is published? C works on the abstract model of low...
27
by: Simon Biber | last post by:
The following Example 3 is given in the 1999 C standard for the function fscanf: I have tested several implementations and none of them get the last case right. In no case does fscanf return 0...
3
by: zade | last post by:
I want to create a library with c interface but with c++ implementation. But I don't know if there exist some potential problems. Any advice? thanks!
3
by: xahlee | last post by:
In the past weeks i've been thinking over the problem on the practical problems of regex in its matching power. For example, often it can't be used to match anything of nested nature, even the most...
6
by: Ralph | last post by:
Hi, I was reading effictive C++ and some other books again and they all tell you about hiding implementation details (proxy/pimpl/inheritance) but they never really explain when to use it. I...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...

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.