dbTalk Databases Forums  

Technical difficulties when using M:N relations?

comp.databases.ibm-db2 comp.databases.ibm-db2


Discuss Technical difficulties when using M:N relations? in the comp.databases.ibm-db2 forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Kai
 
Posts: n/a

Default Technical difficulties when using M:N relations? - 08-04-2011 , 10:55 AM






Hi there,

This question might be a little off-topic because it isn't related to
DB2 - sorry about that.

I am reading the book about DBMS from Thomas Connolly to gain deeper
understanding about DBMS' and stuggle with one of the recommendations
of the logical design. Connolly "recommends" to replace M:N with two
1:N relations. Unfortunatelly, he didn't give a good reason for that
and it seems to work on DB2 9.7.4 though.

Is there a reason to avoid M:N relations (in general)?

Thanks in advance.

Kai

Reply With Quote
  #2  
Old   
Kai
 
Posts: n/a

Default Re: Technical difficulties when using M:N relations? - 08-04-2011 , 11:42 AM






What I ment to say was: the "idea" of a table, that connects two other
tables, works for me without massive performance penalties on 9.7.4.


On 2011-08-04 17:55:50 +0200, Kai said:

Quote:
Hi there,

This question might be a little off-topic because it isn't related to
DB2 - sorry about that.

I am reading the book about DBMS from Thomas Connolly to gain deeper
understanding about DBMS' and stuggle with one of the recommendations
of the logical design. Connolly "recommends" to replace M:N with two
1:N relations. Unfortunatelly, he didn't give a good reason for that
and it seems to work on DB2 9.7.4 though.

Is there a reason to avoid M:N relations (in general)?

Thanks in advance.

Kai

Reply With Quote
  #3  
Old   
Lennart Jonsson
 
Posts: n/a

Default Re: Technical difficulties when using M:N relations? - 08-04-2011 , 03:51 PM



On 2011-08-04 18:42, Kai wrote:
Quote:
What I ment to say was: the "idea" of a table, that connects two other
tables, works for me without massive performance penalties on 9.7.4.
I'm not sure I follow, but I'm not familiar with Connolys book. Let's
say we have two relations STUDENTS and COURSES that have a N:M
relationship, that is a student may take many courses, and a course may
have many students.

ENROLL
STUDENTS : N ------ M : COURSES


When implemented in sql the relationship ENROLL usually becomes a new
relation (aka table). The relationship between ENROLL and STUDENTS is
typically 1:N and the same goes for COURSES and ENROLL. If I get it
right you seem to accept this above but question it below?


/Lennart


Quote:

On 2011-08-04 17:55:50 +0200, Kai said:

Hi there,

This question might be a little off-topic because it isn't related to
DB2 - sorry about that.

I am reading the book about DBMS from Thomas Connolly to gain deeper
understanding about DBMS' and stuggle with one of the recommendations
of the logical design. Connolly "recommends" to replace M:N with two
1:N relations. Unfortunatelly, he didn't give a good reason for that
and it seems to work on DB2 9.7.4 though.

Is there a reason to avoid M:N relations (in general)?

Thanks in advance.

Kai


Reply With Quote
  #4  
Old   
Kai
 
Posts: n/a

Default Re: Technical difficulties when using M:N relations? - 08-05-2011 , 03:25 AM



Quote:
I'm not sure I follow, but I'm not familiar with Connolys book. Let's
say we have two relations STUDENTS and COURSES that have a N:M
relationship, that is a student may take many courses, and a course may
have many students.

ENROLL
STUDENTS : N ------ M : COURSES


When implemented in sql the relationship ENROLL usually becomes a new
relation (aka table). The relationship between ENROLL and STUDENTS is
typically 1:N and the same goes for COURSES and ENROLL. If I get it
right you seem to accept this above but question it below?
This is how I've done that in the past (and how I've learned it at
University). Connolly says, however, we should always replace M:N
relations with two 1:N relations, like this:

ENROL
STUDENTS : N ----- 1: REGISTRY : 1 ----- M : COURSES

Well, this is how it is implemented but, and that is what is wondering
me, Connolly says we should do this while creating the logical design.
For me, this makes it more difficult to read and to understand after a
while.

Let me rephrase my first question: is it bad practice to use M:N
relations in ERDs? If so, why?

Thanks in advance
Kai



Quote:
/Lennart




On 2011-08-04 17:55:50 +0200, Kai said:

Hi there,

This question might be a little off-topic because it isn't related to
DB2 - sorry about that.

I am reading the book about DBMS from Thomas Connolly to gain deeper
understanding about DBMS' and stuggle with one of the recommendations
of the logical design. Connolly "recommends" to replace M:N with two
1:N relations. Unfortunatelly, he didn't give a good reason for that
and it seems to work on DB2 9.7.4 though.

Is there a reason to avoid M:N relations (in general)?

Thanks in advance.

Kai

Reply With Quote
  #5  
Old   
Lennart Jonsson
 
Posts: n/a

Default Re: Technical difficulties when using M:N relations? - 08-05-2011 , 06:23 AM



On 2011-08-05 10:25, Kai wrote:
[...]
Quote:
Well, this is how it is implemented but, and that is what is wondering
me, Connolly says we should do this while creating the logical design.
For me, this makes it more difficult to read and to understand after a
while.

Let me rephrase my first question: is it bad practice to use M:N
relations in ERDs? If so, why?
Ok, I see now that I probably misread your post. At the logical level I
see no reason to remove M:N relationships. IMHO doing so will only
clutter the logical view with unnecessary details.

/Lennart

Reply With Quote
  #6  
Old   
Yonghang Wang
 
Posts: n/a

Default Re: Technical difficulties when using M:N relations? - 08-17-2011 , 09:36 AM



I believe we have good reason though in real world we may just keep it for some special consideration or just by non-mature modeling practice.

as we're considering modeling, FK is very important and it is how tables become "related". so the argument is, with many-to-many, we lose the abilityof dbms enforced integrity by foreign keys. or say, a normalized model cannot represent many-to-many with foreign keys.

Reply With Quote
  #7  
Old   
Kai
 
Posts: n/a

Default Re: Technical difficulties when using M:N relations? - 08-19-2011 , 06:33 AM



Interesing point. I've never seen it from that perspective!


On 2011-08-17 16:36:32 +0200, Yonghang Wang said:

Quote:
I believe we have good reason though in real world we may just keep it
for some special consideration or just by non-mature modeling practice.

as we're considering modeling, FK is very important and it is how
tables become "related". so the argument is, with many-to-many, we
lose the ability of dbms enforced integrity by foreign keys. or say, a
normalized model cannot represent many-to-many with foreign keys.


Reply With Quote
  #8  
Old   
--CELKO--
 
Posts: n/a

Default Re: Technical difficulties when using M:N relations? - 08-20-2011 , 10:26 AM



Quote:
Connolly says, however, we should always replace M:N relations with two 1:N relations, l
CREATE TABLE Husbands
(husband_id INTEGER NOT NULL PRIMARY KEY,
…);

CREATE TABLE Wives
(wife_id INTEGER NOT NULL PRIMARY KEY,
…);

The reason for putting the relationship into a separate table is to
control cardinality (1:1, 1:m, n:m), degree (unary, binary, n-ary) and
optionality (optional or mandatory)

CREATE TABLE Marriages
(husband_id INTEGER NOT NULL UNIQUE
REFERENCES Husbands (husband_id)
ON DELETE CASCADE,
wife_id INTEGER NOT NULL UNIQUE
REFERENCES Wives(wife_id)
ON DELETE CASCADE,
<< Marriage attributes, like wedding date >>);

The NOT NULL and CASCADE make (husband, wife) compulsory, Try the rest
of the combinations of just uniqueness:

CREATE TABLE Polygamy
(husband_id INTEGER NOT NULL
REFERENCES Husbands (husband_id)
ON DELETE CASCADE,
wife_id INTEGER NOT NULL UNIQUE
REFERENCES Wives(wife_id)
ON DELETE CASCADE,
<< attributes >>);

CREATE TABLE Polyandry
(husband_id INTEGER NOT NULL UNIQUE
REFERENCES Husbands (husband_id)
ON DELETE CASCADE,
wife_id INTEGER NOT NULL
REFERENCES Wives(wife_id)
ON DELETE CASCADE,
<< attributes >>);

CREATE TABLE Dating_Couples
(husband_id INTEGER NOT NULL
REFERENCES Husbands (husband_id)
ON DELETE CASCADE,
wife_id INTEGER NOT NULL
REFERENCES Wives(wife_id)
ON DELETE CASCADE,
PRIMARY KEY (husband_id, wife_id),
<< attributes >>);

Now play with NULL|NOT NULL for optional|mandatory.

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.