Relational Database Modeling II
Relational Database Modeling II
Modeling II
publishe
PUBLISHER BOOK
s
Library Database (cont’d)
Step 3. Determine relationship type. Ask:
Each book is written by how many authors? Each author
writes how many books?
Each book may be authored by zero (anonymous), one, or more than
one author and each author may write zero, one, or more than one
book. The relationship type is many-to-many or:
M N
AUTHOR writes BOOK
since each author does not have to write a book (may make CD)
the level of participation is optional for both sides of the
relationship of AUTHOR-writes-BOOK combination
M N
AUTHOR writes BOOK
(0, N) (0, N)
For the PUBLISHER-publishes-BOOK combination, the level of
participation for PUBLISHER is optional (publishers do not
necessarily have to publish a book, perhaps newsletters) and the
level of participation for the BOOK side is mandatory (each book
must have a publisher)
1 publishe
N
PUBLISHER BOOK
s
(0, N) (1,1)
Library Database (cont’d)
Step 5. Assign an identifier for each entity
AuthorID, ISBN, PublisherID
publishes
1
(0,N)
PUBLISHER
PublisherID, ...
Library Database (cont’d)
Step6. Draw completed E-R diagram - resolve
M:N relationships
1 M M 1
AUTHOR writes BOOK ISBN, ...
(0,N) (1,1) (1,1) (0,N) M (1,1)
AuthorID, ... AuthorID,ISBN, ...
publishes
1 (0,N)
PUBLISHER
PublisherID, ...
E-R Modeling: University Example
A database is to be set up to record information about
faculty, the courses they teach, and the students who take
courses. Some courses are taught by teams of faculty
members.
Step 1. Identify entity types
FACULTY COURSE STUDENT
teaches zero, one, or two courses. We are told some courses are
taught by zero, one, two, or three faculty. This is a many-to-many
relationship.
M N
FACULTY teaches COURSE
M N
STUDENT takes COURSE
University Example (cont’d)
Step 4. Determine level of participation
FACULTY-teaches-COURSE - level of participation is optional,
since sometimes Faculty do not have to teach (e.g., sabbatical);
similarly, a course may not have anyone interested in teaching it
M N
FACULTY teaches COURSE
(0,2) (0,3)
STUDENT-takes-COURSE - level of participation is mandatory
since students must take at least one course; a course, however, may
or may not have students taking it
M N
STUDENT takes COURSE
(1,6) (0,30)
University Example (cont’d)
Step 5. Assign an identifier for each entity
FacultyID, CourseID, StudentID
Step 6. Draw completed E-R diagram
M N
CourseID, ... COURSE taken by STUDENT
taught by
(0,2) N
FACULTY
FacultyID, ...
University Example (cont’d)
You are now told that in addition to the relationships given, each
student is assigned a faculty advisor who gives direction in choosing
courses.
Use occurrences diagram to visualize relationship between entities
We are told each student is advised by exactly one faculty advisor.
We can assume that each faculty member advises zero, one, or more
students. This means the additional relationship is of type one-to-
many or 1:M.
The STUDENT is on the many side of the relationship and must be
advised therefore, faculty is mandatory to student; FACULTY on the
one side of the relationship may or may not have a student, therefore
student is optional to faculty.
1 M
FACULTY advises STUDENT
(0,N) (1,1)
University Example (cont’d)
Step 6. Draw completed E-R diagram
1 M M 1
StudentID, ... STUDENT takes COURSE CourseID, ...
supertype
CLIENT CONTRACT
1 m
subtype