Sie sind auf Seite 1von 6

INT642 Database Management System

1 of 6

Entity Relationship Model

Entity Relationship Model


Exercise + Solution
1. Given the following constraints:
A country may consist of multiple parts where each part belongs to one country
and each part is located on one continent; e.g., Russia consists of a western part
in Europe and an eastern part in Asia.
Each city is located on one part of a country and each country has one capital
city; e.g., Bangkok and Lopburi are in the central part of Thailand; Bangkok is the
capital city of Thailand.
Each country may participate in many organizations and each organization may
have many countries as members; e.g., Thailand and US are members of WHO;
Thailand is a member of ASEAN and a member of WHO.
Complete the following E-R diagram (by adding multiplicity using 1 and *) and
convert it to a set of tables, each of which is associated with a primary key and
foreign keys (when applicable).
name

founder

organization

since
join

name

leader

country 1

capital

1
name

of

area

continent 1

1
city

on

*
part 1

name

name

population

in

direction

Solution
continent (name, area);
organization (name, founder);
country (name, leader, capital)
FK(capital) to city;
orgMember (orgName, countryName, since)
FK(orgName) to organization,
FK(countryName) to country;
part (countryName, partName, direction, continentName)
FK(countryName) to country,
FK(continentName) to continent;
city (name, population, countryName, partName)
FK(countryName, partName) to part;

Kriengkrai Porkaew
porkaew@it.kmutt.ac.th

June 17, 2002

MSc(IT), KMUTT

INT642 Database Management System

2 of 6

Entity Relationship Model

2. Given a video rental system consisting of 6 entities - Customer, VideoTitle, Category,


Rating, and VideoCopy -- with the following constraints:
Each video title may have multiple copies so that many customers can rent the
same movie (title) at the same time. Each copy can be rented by at most one
customer at a time.
A customer may rent multiple copies (usually each copy from different titles) at a
time but each copy must be rented by at most one customer at a time.
Each video title is associated with one rating (e.g., G, PG, PG-13, R) and one or
more categories (e.g., Suspense, Comedy, Documentary, Action).
Complete the following E-R diagram (by adding cardinality), and convert it to a set of
tables, each of which is associated with a primary key and foreign keys (when
applicable).
code

rating

ID

name

description

name

rate

title

actor

in

type

description

category

of

address

customer 1

director

rent

date

number

*
copy
media

Solution
customer (ID, name, address);
rating (code, ratingDescription);
category (type, categoryDescription);
title (name, director, ratingCode)
FK(ratingCode) to rating;
actor (actorName, titleName)
FK(titleName) to title;
titleCategory (titleName, categoryType)
FK(titleName) to title,
FK(categoryName) to category;
copy (titleName, copyNumber, media, rentDate, renter)
FK(titleName) to title,
FK(renter) to customer;

Kriengkrai Porkaew
porkaew@it.kmutt.ac.th

June 17, 2002

MSc(IT), KMUTT

INT642 Database Management System

3 of 6

Entity Relationship Model

3. Construct an E-R diagram from the following set of tables. State all reasonable
assumption that you make.
instructor (IID, iName, office);
student (SID, sName, advisor, degree)
FK (advisor) to instructor;
course (code, title);
prerequisite (code, prerequisiteCode);
FK (code) to course and FK (preCode) to course;
classroom (number, floor, building);
lecture (code, semester, lecturer, roomNo, time);
FK (code) to course, FK (lecturer) to instructor, and FK (roomNo) to classroom;
registration (SID, code, semester, grade)
FK (SID) to student and FK (code, semester) to lecturer;
Solution
Using ER Notation:

number

code

title

floor

course

prerequisite

building

classroom

at

offer

name

lecture

IID

semester
time

office

instructor

teach

grade

take

SID

student

advise

name
degree

Using UML Notation:


course
code
title

classroom
number
floor
1
building
instructor
IID
name
office

offer
at

teach
1

*
advise

Kriengkrai Porkaew
porkaew@it.kmutt.ac.th

*
*prerequisite of

*
lecture
semester
time

take

*
student
SID
name
degree
June 17, 2002

registration
grade

MSc(IT), KMUTT

INT642 Database Management System

4 of 6

Entity Relationship Model

4. Suppose that we have the following requirements for a university database that is use
to keep track of students transcripts:
The university keeps track of each students name; student number; address and
phone; major department; minor department (if any); and degree program (i.e.,
B.A., B.S., , or Ph.D.). Student number is unique for each student.
Each department is described by name, department code, office number, office
phone. Department code is unique for each department.
Each course has a course name, description, course number, number of semester
hours (credit), and offering department. The course number is unique for each
course.
Each section has an instructor name, semester, year, course number, and section
number. The section number distinguishes different sections of the same course
that are taught during the same semester and year; its values are 1, 2, 3, , up to
the total number of the sections taught during each semester.
A grade record refers to each student, a particular section, and a grade.
Construct an ER diagram corresponding to the above requirement and convert it to a
set of tables, each of which is associated with a primary key and foreign keys (when
applicable).
Solution
Using ER Notation:
name
code

office
phone

department

number

minor

degree

student

major

Using UML Notation:

offer
*

course
number
name
description
credit

1
of

major
minor

instructor

section

of

name

year

semester
secNo

credit

course

offer

SID

department 1
code
name
1
office
phone
1

description

name

grade
record

section
sectionNo
semester
year
instructor

*
take
*
*
student
SID
*
name
degree

record
grade

department (code, name, office, phone);


course (number, name, description, credit, dept) FK(dept) to department;
student (SID, name, degree, major, minor)
FK(major) to department and FK(minor) to department;
section (courseNo, secNo, semester, year, instructor) FK(courseNo) to course;
record (SID, courseNo, secNo, semester, year, grade)
FK(SID) to student and FK(courseNo, secNo, semester, year) to section;
Kriengkrai Porkaew
porkaew@it.kmutt.ac.th

June 17, 2002

MSc(IT), KMUTT

INT642 Database Management System

5 of 6

Entity Relationship Model

5. A department store records data of its employees, departments, and products it sells.
Each employee has a unique id, a name, an address, a phone number, and the
department he/she works for. Each employee works for one department only. Each
department has a unique name, a phone number, and a manager, who is an
employee. Each product has a unique product code, a name, a product type, and its
price. Each product type is sold by one department only. Design a conceptual
schema for this requirement and convert it to a set of tables, each of which is
associated with a primary key and foreign keys (when applicable).
Solution
Using ER Notation:
name

address

ID

work for

employee

phone

name

phone
manage

department
name
code

sell

type

product type

of

price

product

Using UML Notation:


work for
employee
ID
name
address
phone

*
1

department
product type
1
*
1
type
name
*
of
phone
sell

*
manage

product
code
name
price

department (name, phone, manager) FK(manager) to employee;


employee (ID, name, address, phone, dept) FK(dept) to department;
productInDepartment (productType, dept) FK(dept) to department;
product (code, name, price, type) FK(type) to productInDepartment;

Kriengkrai Porkaew
porkaew@it.kmutt.ac.th

June 17, 2002

MSc(IT), KMUTT

INT642 Database Management System

6 of 6

Entity Relationship Model

Alternative Extended ER Notation:


PERSON
incomplete

overlapping

EMPLOYEE

STUDENT
complete

subtype

d
UNDERGRAD

GRAD

disjoint

STAFF

LECTURER

Equivalent UML Notation:


PERSON
{incomplete, overlapping}
STUDENT
{complete, disjoint}
UNDERGRAD

Kriengkrai Porkaew
porkaew@it.kmutt.ac.th

GRAD

EMPLOYEE
{disjoint}
STAFF

June 17, 2002

LECTURER

MSc(IT), KMUTT

Das könnte Ihnen auch gefallen