dbTalk Databases Forums  

object model to table design mapping problem

comp.databases.object comp.databases.object


Discuss object model to table design mapping problem in the comp.databases.object forum.



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

Default object model to table design mapping problem - 07-16-2004 , 01:16 AM






Given the object model, I want to design the database tables. The object
model is that school has a list of courses.

The following are my 2 approaches. My question is which one is better?
Should table COURSE has the foreign key of table SCHOOL? Or table SCHOOL has
the
foreign key of table COURSE?

Please advise the design principles here. Thanks!!

Approach #1: table COURSE has the foreign key of NAME in table SCHOOL
================================================== ==
CREATE TABLE SCHOOL
( NAME varchar(50) not null,
PRINCIPAL varchar(12),
PRIMARY KEY(NAME)
);

CREATE TABLE COURSE
( NAME varchar(50) not null,
SCHOOLNAME varchar(50),
FOREIGN KEY(SCHOOLNAME) REFERENCES SCHOOL(NAME),
PRIMARY KEY(NAME)
);

Approach #2: table SCHOOL has the foreign key of NAME in table COURSE
==================================================
CREATE TABLE COURSE
( NAME varchar(50) not null,
PRIMARY KEY(NAME)
);

CREATE TABLE SCHOOL
( NAME varchar(50) not null,
PRINCIPAL varchar(12),
PRIMARY KEY(NAME),
COURSENAME varchar(50),
FOREIGN KEY(COURSENAME) REFERENCES COURSE(NAME),
);







Reply With Quote
  #2  
Old   
Mark Nicholls
 
Posts: n/a

Default Re: object model to table design mapping problem - 07-16-2004 , 07:55 AM






Quote:
Given the object model, I want to design the database tables. The object
model is that school has a list of courses.

The following are my 2 approaches. My question is which one is better?
Should table COURSE has the foreign key of table SCHOOL? Or table SCHOOL has
the
foreign key of table COURSE?

Please advise the design principles here. Thanks!!

Approach #1: table COURSE has the foreign key of NAME in table SCHOOL
================================================== ==
CREATE TABLE SCHOOL
( NAME varchar(50) not null,
PRINCIPAL varchar(12),
PRIMARY KEY(NAME)
);

CREATE TABLE COURSE
( NAME varchar(50) not null,
SCHOOLNAME varchar(50),
FOREIGN KEY(SCHOOLNAME) REFERENCES SCHOOL(NAME),
PRIMARY KEY(NAME)
);

Approach #2: table SCHOOL has the foreign key of NAME in table COURSE
==================================================
CREATE TABLE COURSE
( NAME varchar(50) not null,
PRIMARY KEY(NAME)
);

CREATE TABLE SCHOOL
( NAME varchar(50) not null,
PRINCIPAL varchar(12),
PRIMARY KEY(NAME),
COURSENAME varchar(50),
FOREIGN KEY(COURSENAME) REFERENCES COURSE(NAME),
);
It depends what you mean by course, if you mean a specific course at a
specific school and a school has many courses i.e a specific course it
taught at one specific school, but a school may teach many courses
then #1 i.e. each entry in course table is the name of the course and
the link to the school that teaches it.

If you mean subject like maths or english and a schools teach many
subjects and a subject is taught by many schools then neither, you
need another table to hold this information.

see

http://www.brunel.ac.uk/~eestcjb/EE2002S/L07.ppt

I think this is pretty much lifted from Object Oriented Modelling and
Design - Rumbaugh.


Reply With Quote
  #3  
Old   
H. S. Lahman
 
Posts: n/a

Default Re: object model to table design mapping problem - 07-16-2004 , 01:31 PM



Responding to Matt...

Quote:
Given the object model, I want to design the database tables. The object
model is that school has a list of courses.

The following are my 2 approaches. My question is which one is better?
Should table COURSE has the foreign key of table SCHOOL? Or table SCHOOL has
the
foreign key of table COURSE?

Please advise the design principles here. Thanks!!
The short answer is: if you are designing a DB, then use Data Modeling. B-)

In this case the rules for placing the referential attribute happen to
be the same and they are dictated by the multiplicity and conditionality
of the relationship.

1 *
[School] --------------- [Course]

The referential attribute must go on the [Course] side. That's the only
place it is unambiguous.

* 1
[School] --------------- [Course]

The referential attribute must go on the [School] side. Ditto.

* *
[School] --------------- [Course]

One needs an association object (index) rather than referential
attributes in the DB. Embedded referential attributes would be
ambiguous on either side.

0..1 1
[School] --------------- [Course]

It should go on the [School] side. The issue here is not ambiguity; it
just makes processing navigation slightly less expensive because there
is no need to check if the relationship is "active" before navigating it.

[Caveat: if navigation is always from the [Course] side, then the
performance benefit for placing it there will usually outweigh the
conditional checks. That, however, becomes academic if one provides
things like auxiliary indices to support joins.]

1 0..1
[School] --------------- [Course]

It should go on the [Course] side. Ditto.

1 1
[School] --------------- [Course]
or
0..1 0..1
[School] --------------- [Course]

It can go on either side. Typically that choice is made based upon DB
performance by placing it on the side from which which navigation is
most common when forming joins. (As a practical matter it is likely
that auxiliary indices will be provided to address join performance.)


*************
There is nothing wrong with me that could
not be cured by a capful of Drano.

H. S. Lahman
hsl (AT) pathfindermda (DOT) com
Pathfinder Solutions -- Put MDA to Work
http://www.pathfindermda.com
(888)-OOA-PATH






Reply With Quote
  #4  
Old   
Bala Paranj
 
Posts: n/a

Default Re: object model to table design mapping problem - 07-17-2004 , 06:00 AM



Check out this excellent article by Mr. Scott Ambler
http://www.agiledata.org/essays/mappingObjects.html
It addresses this issue. Like the other poster said, it depends on
what you are trying to do with your data modeling. This paper suggests
that you would have the one side of the table have a foreign key
towards the many side of the table. I took a quick glance and did not
see any explanation for why. If you can find it, please share it.

Bala
69BP1N-NCRDU
http://uml.zepho.com

Quote:
Given the object model, I want to design the database tables. The object
model is that school has a list of courses.

The following are my 2 approaches. My question is which one is better?
Should table COURSE has the foreign key of table SCHOOL? Or table SCHOOL has
the
foreign key of table COURSE?

Please advise the design principles here. Thanks!!

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.