Sunteți pe pagina 1din 14

Chapter 7: Data Modeling Using the Entity-Relationship (ER) Model

CHAPTER 7: DATA MODELING USING THE ENTITY-RELATIONSHIP (ER) MODEL


Answers to Selete! E"er#ses
7$%& - Consider the following set of requirements for a U!"ER#!$% data&ase that is used to
'eep tra(' of students) trans(ripts* $his is similar &ut not identi(al to the data&ase shown in
+igure ,*-:
(a) $he uni.ersity 'eeps tra(' of ea(h student)s name/ student num&er/ so(ial se(urity
num&er/ (urrent address and phone/ permanent address and phone/ &irthdate/ se0/ (lass
(freshman/ sophomore/ ***/ graduate)/ ma1or department/ minor department (if any)/ and
degree program (2*3*/ 2*#*/ ***/ 4h*D*)* #ome user appli(ations need to refer to the (ity/
state/ and 5ip of the student)s permanent address/ and to the student)s last name* 2oth
so(ial se(urity num&er and student num&er ha.e unique .alues for ea(h student*
(&) Ea(h department is des(ri&ed &y a name/ department (ode/ offi(e num&er/ offi(e phone/
and (ollege* 2oth name and (ode ha.e unique .alues for ea(h department*
(() Ea(h (ourse has a (ourse name/ des(ription/ (ourse num&er/ num&er of semester hours/
le.el/ and offering department* $he .alue of (ourse num&er is unique for ea(h (ourse*
(d) Ea(h se(tion has an instru(tor/ semester/ year/ (ourse/ and se(tion num&er* $he se(tion
num&er distinguishes different se(tions of the same (ourse that are taught during the same
semester6year7 its .alues are ,/ -/ 8/ ***/ up to the num&er of se(tions taught during ea(h
semester*
(e) 3 grade report has a student/ se(tion/ letter grade/ and numeri( grade (9/ ,/ -/ 8/
: for +/ D/ C/ 2/ 3/ respe(ti.ely)*
Design an ER s(hema for this appli(ation/ and draw an ER diagram for that s(hema*
#pe(ify 'ey attri&utes of ea(h entity type and stru(tural (onstraints on ea(h relationship type*
ote any unspe(ified requirements/ and ma'e appropriate assumptions to ma'e the
spe(ifi(ation (omplete*
Answer:
Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
,
Chapter 7: Data Modeling Using the Entity-Relationship (ER) Model
7$%7 - Composite and multi-.alued attri&utes (an &e nested to any num&er of le.els*
#uppose we want to design an attri&ute for a #$UDE$ entity type to 'eep tra(' of pre.ious
(ollege edu(ation* #u(h an attri&ute will ha.e one entry for ea(h (ollege pre.iously attended/
and this entry is (omposed of: (ollege name/ start and end dates/ degree entries (degrees
awarded at that (ollege/ if any)/ and trans(ript entries ((ourses (ompleted at that (ollege/ if
any)* Ea(h degree entry is formed of degree name and the month and year it was awarded/
and ea(h trans(ript entry is formed of a (ourse name/ semester/ year/ and grade* Design an
attri&ute to hold this information* Use the (on.entions of +igure 7*;*
Answer:
< 4re.iousEdu(ation ( Collegeame/ #tartDate/ EndDate/
< Degree (Degreeame/ Month/ %ear) =/
< $rans(ript (Courseame/ #emester/ %ear/ >rade) = ) =
Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
-
7$%&
Chapter 7: Data Modeling Using the Entity-Relationship (ER) Model
'$%( - #how an alternati.e design for the attri&ute des(ri&ed in E0er(ise 7*,7 that uses only
entity types (in(luding wea' entity types if needed) and relationship types*
Answer:
$his e0ample illustrates a per(ei.ed wea'ness of the ER model/ whi(h is: how does the
data&ase designer de(ide what to model as an entity type and what to model as a
relationship type* !n our solution/ we (reated a wea' entity type 3$$ED3CE7 ea(h (wea')
entity in 3$$ED3CE represents a period in whi(h a #$UDE$ attended a parti(ular
C?@@E>E/ and is identified &y the #$UDE$ and the #tartDate of the period* Aen(e/ the
#tartDate attri&ute is the partial 'ey of 3$$ED3CE* Ea(h 3$$ED3CE entity is related
to one C?@@E>E and 5ero or more DE>REEs (the degrees awarded during that attendan(e
period)* $he $R3#CR!4$ of the #$UDE$ during ea(h attendan(e period is modeled as a
wea' entity type/ whi(h gi.es the re(ords of the student during the attendan(e period* Ea(h
(wea') entity in $R3#CR!4$ gi.es the re(ord of the sudent in one (ourse during the
attendan(e period/ as shown in the ER diagram &elow* ?ther ER s(hema designs are also
possi&le for this pro&lem*
Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
8
7$%&
Chapter 7: Data Modeling Using the Entity-Relationship (ER) Model
7$%) - Consider the ER diagram of +igure 7*-9/ whi(h shows a simplified s(hema for an
airline reser.ations system* E0tra(t from the ER diagram the requirements and (onstraints
that resulted in this s(hema* $ry to &e as pre(ise as possi&le in your requirements and
(onstraints spe(ifi(ation*
Answer:
(,) $he data&ase represents ea(h 3!R4?R$/ 'eeping its unique 3irportCode/ the 3!R4?R$
ame/ and the City and #tate in whi(h the 3!R4?R$ is lo(ated*
(-) Ea(h airline +@!>A$ has a unique num&er/ the 3irline for the +@!>A$/ and the Bee'days
on whi(h the +@!>A$ is s(heduled (for e0ample/ e.ery day of the wee' e0(ept #unday (an
&e (oded as C7)*
(8) 3 +@!>A$ is (omposed of one or more +@!>A$ @E>s (for e0ample/ flight num&er
C?,--8 from ew %or' to @os 3ngeles may ha.e two +@!>A$ @E>s: leg , from ew %or'
to Aouston and leg - from Aouston to @os 3ngeles)* Ea(h +@!>A$ @E> has a DE43R$URE
3!R4?R$ and #(heduled Departure $ime/ and an 3RR!"3@ 3!R4?R$ and #(heduled
3rri.al $ime*
(:) 3 @E> !#$3CE is an instan(e of a +@!>A$ @E> on a spe(ifi( Date (for e0ample/
C?,--8 leg , on Duly 89/ ,EFE)* $he a(tual Departure and 3rri.al 3!R4?R$s and
$imes are re(orded for ea(h flight leg after the flight leg has &een (on(luded* $he
um&er of a.aila&le seats and the 3!R4@3E used in the @E> !#$3CE are also 'ept*
(;) $he (ustomer RE#ER"3$!?s on ea(h @E> !#$3CE in(lude the Customer ame/
4hone/ and #eat um&er(s) for ea(h reser.ation*
Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
:
Chapter 7: Data Modeling Using the Entity-Relationship (ER) Model
(G) !nformation on 3!R4@3Es and 3!R4@3E $%4Es are also 'ept* +or ea(h 3!R4@3E
$%4E (for e0ample/ DC-,9)/ the $ypeame/ manufa(turing Company/ and
Ma0imum um&er of #eats are 'ept* $he 3!R4?R$s in whi(h planes of this type
C3 @3D are 'ept in the data&ase* +or ea(h 3!R4@3E/ the 3irplane!d/ $otal num&er of
seats/ and $%4E are 'ept*
7$*+ - o solution pro.ided*
7$*% -
3dditional information:
- $here are :8; (ongresspersons in the U*#* Aouse of Representati.es*
- #tates ha.e &etween one (3H/ DE/ M$/ D/ #D/ "$/ and B%) and ;- (C3)
representati.es*
- M represents num&er of &ills during the --year session*
$he resulting ER Diagram is shown in +igure 3*
7$** - 3 data&ase is &eing (onstru(ted to 'eep tra(' of the teams and games of a sports
league* 3 team has a num&er of players/ not all of whom parti(ipate in ea(h game*
!t is desired to 'eep tra(' of the players parti(ipating in ea(h game for ea(h team/ the
positions they played in that game/ and the result of the game* $ry to design an ER s(hema
diagram for this appli(ation/ stating any assumptions you ma'e* Choose your fa.orite sport
(so((er/ foot&all/ &ase&all ***)*
Answer:
$he following design may &e used for a &ase&all league* Aere/ we assumed that ea(h game
in the s(hedule is identified &y a unique >ameI/ and a game is also identified uniquely &y
the (om&ination of Date/ starting $ime/ and +ield where it is played* $he 4erforman(e
Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
;
Chapter 7: Data Modeling Using the Entity-Relationship (ER) Model
attri&ute of 43R$!C!43$E is used to store information on the indi.idual performan(e of ea(h
player in a game* $his attri&ute (an &e designed to 'eep the information needed for
statisti(s/ and may &e quite (omple0* ?ne possi&le design for the 4erforman(e attri&ute may
&e the following (using the notation of +igure 7*F):
4erforman(e( <Aitting(3t2atI/ !nningI/ Ait$ype/ Runs/ Runs2atted!n/ #tolen2ases)=/
<4it(hing(!nningI/ Aits/ Runs/ EarnedRuns/ #tri'e?uts/ Bal's/ ?uts/
2al's/ Bild4it(hes)=/
<Defense(!nningI/ <+ieldingRe(ord(4osition/ 4ut?uts/ 3ssists/ Errors)=)= )
Aere/ performan(e is a (omposite attri&ute made up of three multi.alued (omponents:
Aitting/ 4it(hing/ and Defense* Aitting has a .alue for ea(h 3t2at of a player/ and re(ords
the Ait$ype (suita&le (oded7 for e0ample/ , for single/ - for dou&le/ 8 for triple/ : for
home run/ 9 for wal'/ -, for stri'eout/ -- for fly out/ ***) and other information
(on(erning the 3t2at* 4it(hing has a .alue for ea(h inning during whi(h the player
pit(hed* Defense has a .alue for ea(h inning a player played a fielding position* Be (an
ha.e a less detailed or a more detailed design for the performan(e of a player in ea(h
game/ depending on how mu(h information we need to 'eep in the data&ase* #uita&le
.ariations of the ER diagram shown &elow (an &e used for other sports*
7$*' - Consider the ER diagram shown in +igure 7*-, for part of a 23H data&ase* Ea(h
&an' (an ha.e multiple &ran(hes/ and ea(h &ran(h (an ha.e multiple a((ounts and loans*
(a) @ist the strong (nonwea') entity types in the ER diagram*
(&) !s there a wea' entity typeJ !f so/ gi.e its name/ its partial 'ey/ and its identifying
relationship*
(() Bhat (onstraints do the partial 'ey and the identifying relationship of the wea' entity type
spe(ify in this diagramJ
Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
G
Chapter 7: Data Modeling Using the Entity-Relationship (ER) Model
(d) @ist the names of all relationship types/ and spe(ify the (min/ma0) (onstraint on ea(h
parti(ipation of an entity type in a relationship type* Dustify your (hoi(es*
(e) @ist (on(isely the user requirements that led to this ER s(hema design*
(f) #uppose that e.ery (ustomer must ha.e at least one a((ount &ut is restri(ted
to at most two loans at a time/ and that a &an' &ran(h (annot ha.e more than
,999 loans* Aow does this show up on the (min/ma0) (onstraintsJ
Answer:
(a) Entity types: 23H/ 3CC?U$/ CU#$?MER/ @?3
(&) Bea' entity type: 23H-2R3CA* 4artial 'ey: 2ran(ho*
!dentifying relationship: 2R3CAE#*
(() $he partial 'ey 2ran(ho in 23H-2R3CA spe(ifies that the same 2ran(ho .alue ay
o((ur under different 23Hs* $he identifying relationship 2R3CAE# spe(ifies that
Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
7
Chapter 7: Data Modeling Using the Entity-Relationship (ER) Model
2ran(ho .alues are uniquely assigned for those 23H-2R3CA entities that are related
to the same 23H entity* Aen(e/ the (om&ination of 23H Code and 2ran(ho together
(onstitute a full identifier for a 23H-2R3CA*
(d) Relationship $ypes: 2R3CAE#/ 3CC$#/ @?3#/ 3-C/ @-C* $he (min/ ma0) (onstraints
are shown &elow*
(e) $he requirements may &e stated as follows: Ea(h 23H has a unique Code/ as well as a
ame and 3ddress* Ea(h 23H is related to one or more 23H-2R3CAes/ and the
2ranho is unique among ea(h set of 23H-2R3CAes that are related to the same 23H*
Ea(h 23H-2R3CA has an 3ddress* Ea(h 23H-2R3CA has 5ero or more @?3# and
5ero or more 3CC$#* Ea(h 3CC?U$ has an 3((to (unique)/ 2alan(e/ and $ype and is
related to e0a(tly one 23H-2R3CA and to at least one CU#$?MER* Ea(h @?3 has a
@oano (unique)/ 3mount/ and $ype and is related to e0a(tly one 23H-2R3CA and to at
least one CU#$?MER* Ea(h CU#$?MER has an ## (unique)/ ame/ 4hone/ and
3ddress/ and is related to 5ero or more 3CC?U$s and to 5ero or more @?3s*
(f) $he (min/ ma0) (onstraints would &e (hanged as follows:
7$*, - Consider the ER diagram in +igure 7*--* 3ssume that an employee may wor' in up to
two departments or may not &e assigned to any department* 3ssume that ea(h department
must ha.e one and may ha.e up to three phone num&ers* #upply (min/ ma0) (onstraints on
this diagram* #tate (learly any additional assumptions you ma'e* Under what (onditions
would the relationship A3#K4A?E &e redundant in this e0ampleJ
Answer:
3ssuming the following additional assumptions:
- Ea(h department (an ha.e anywhere &etween , and ,9 employees*
- Ea(h phone is used &y one/ and only one/ department*
- Ea(h phone is assigned to at least one/ and may &e assigned to up to ,9 employees*
- Ea(h employee is assigned at least one/ &ut no more than G phones*
$he resulting ER Diagram will ha.e the (min/ ma0) (onstraints shown in +igure 3*
Relationship A3#-4A?E would &e redundant under the following (onditions:
- Ea(h employee is assigned all of the phones of ea(h department that he6she wor's in*
Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
F
Chapter 7: Data Modeling Using the Entity-Relationship (ER) Model
- 3n employee (annot ha.e any other phones outside the departments he6she wor's is*
EM4@?%EE
4A?E
DE43R$ME$
A3#-4A?E C?$3!#
B?RH#-!
(9/ -)
(,/ 8)
(,/ ,9)
(,/ ,9) (,/ ,)
(,/ G)
7$*- - Consider the ER diagram in +igure 7*-8* 3ssume that a (ourse may or may not use a
te0t&oo'/ &ut that a te0t &y definition is a &oo' that is used in some (ourse* 3 (ourse may not
use more than fi.e &oo's* !nstru(tors tea(h from two to four (ourses* #upply (min/ ma0)
(onstraints on this diagram* #tate (learly any additional assumptions you ma'e* !f we add
the relationship 3D?4$# &etween !#$RUC$?R and $EC$/ what (min/ ma0) (onstraints
would you put on itJ BhyJ
Answer:
3ssuming the following additional assumptions:
- Ea(h (ourse is taught &y e0a(tly one instru(tor*
- Ea(h te0t&oo' is used &y one and only one (ourse*
- 3n instru(tor does not ha.e to adopt a te0t&oo' for all (ourses*
- !f a te0t e0ists:
- KKKit is used in some (ourse/
- KKKhen(e it is adopted &y some instru(tor who tea(hes that (ourse*
- 3n instru(tor is (onsidered to adopt a te0t if it is used in some (ourse taught
- &y that instru(tor*
$he resulting ER Diagram will ha.e the (min/ ma0) (onstraints shown in +igure 2*
7$*& - Consider an entity type SECTION in a UNIVERSITY data&ase/ whi(h des(ri&es the
se(tion offerings of (ourses* $he attri&utes of SECTION are #e(tionum&er/ #emester/
%ear/ Courseum&er/ !nstru(tor/ Roomo (where se(tion is taught)/ 2uilding (where se(tion
is taught)/ Bee'days (domain is the possi&le (om&inations of wee'days in whi(h a se(tion
(an &e offered <MB+/ MB/ $$/ et(*=)* 3ssume tat #e(tionum&er is unique for ea(h (ourse
Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
E
Chapter 7: Data Modeling Using the Entity-Relationship (ER) Model
within a parti(ular semester6year (om&ination (that is/ if a (ourse if offered multiple times
during a parti(ular semester/ its se(tion offerings are num&ered ,/ -/ 8/ et(*)* $here are
se.eral (omposite 'eys for SECTION/ and some attri&ute sare (omponents of more than one
'ey* !dentify three (omposite 'eys/ and show how they (an &e represented in an ER s(hema
diagram*
Answer:
7$*7 - Cardinality ratios often di(tate the detailed design of a data&ase* $he (ardinality ratio
depends on the real-world meaning of the entity types in.ol.ed and is defined &y the spe(ifi(
appli(ation* +or the &inary relationships &elow/ suggest (ardinality ratios &ased on (ommon-
sense meaning of the entity types* Clearly state any assumptions you ma'e*
Entity , Cardinality Ratio Entity -
,* #tudent #o(ial#e(urityCard
-* #tudent $ea(her
8* ClassRoom Ball
:* Country Current4resident
;* Course $e0t2oo'
G*
!tem (that (an &e
found in an order)
?rder
Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
,9
Chapter 7: Data Modeling Using the Entity-Relationship (ER) Model
7* #tudent Class
F* Class !nstru(tor
E* !nstru(tor ?ffi(e
,9*
E-&ay 3u(tion
item
E-&ay &id

Answer:
Entity , Cardinality Ratio Entity -
,* #tudent
,-many
3 student may ha.e more
than one so(ial se(urity
(ard (legally with the
same unique so(ial
se(urity num&er)/ and
e.ery so(ial se(urity
num&er &elongs to a
unique student*
#o(ial#e(urityCard
-* #tudent
Many-many
>enerally students are
taught &y many tea(hers
and a tea(her tea(hes
many students*
$ea(her
8* ClassRoom
Many-many
DonLt forget that the wall
is usually shared &y
ad1a(ent rooms*
Ball
:* Country
,-,
3ssuming a normal
(ountry under normal
(ir(umstan(es ha.ing one
president at a time*
Current4resident
;* Course
Many-many
3 (ourse may ha.e many
te0t&oo's and a te0t &oo'
may &e pres(ri&ed for
different (ourses*
$e0t2oo'
Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
,,
Chapter 7: Data Modeling Using the Entity-Relationship (ER) Model
G*
!tem (that (an &e
found in an order)
Many-many
3ssuming the same item
(an appear in different
orders*
?rder
7* #tudent
Many-many
?ne student may ta'e
se.eral (lasses* E.ery
(lass usually has se.eral
students*
Class
F* Class
Many-to-,
3ssuming that e.ery (lass
has a unique instru(tor* !n
(ase instru(tors were
allowed to team tea(h/
this will &e many-many*
!nstru(tor
E* !nstru(tor
,-,
3ssuming e.ery instru(tor
has only one offi(e and it
is not shared* !n (ase of
offi(es shared &y -
instru(tors/ the
relationship will &e --,*
Con.ersely/ if an
instru(tor has a 1oint
appointment (in two
departments) and offi(es
in &oth departments/ then
the relationship will &e ,-
-* !n a .ery general (ase/
it may &e many-many*
?ffi(e
,9*
E-&ay 3u(tion
item
,-many
, item has many &ids and
a &id is unique to an item
(assuming a regular
au(tion format)*
E-&ay &id
7$*(-7$*) M o solutions pro.ided*
'$'+ - !llustrate the UM@ Diagram for e0er(ise 7*,G* %our UM@ design should o&ser.e the
following requirements:
a* $he student should ha.e the a&ility to (ompute his6her >43 and add or drop ma1ors
and minors*
Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
,-
Chapter 7: Data Modeling Using the Entity-Relationship (ER) Model
&* Ea(h department should &e to a&le add or delete (ourses and hire or terminate
fa(ulty*
(* Ea(h instru(tor should &e a&le to assign or (hange a grade to a student for a (ourse*
Note: #ome of these fun(tions may &e spread o.er multiple (lasses*
Answer:

Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
COURSE
CourseName
Description
CourseNumber: {Course}
SemesterHours
Level
Department
SECTION
Instructor
Semester
ear
CourseNumber
SectionNumber: {!"#"$}
%R&DE RE'ORT
Stu(entNumber
SectionNumber
Letter%ra(e: {&")"C"D"*}
Number%ra(e: {+"!"#","-}
'RERE.UISITE
CourseNumber
'rere/uisiteNumber
STUDENT
Name:
0Name1
Stu(entNumber
SocialSecNumber
Current&((ress:
0&((ress1
Current'2one:
0'2one1
'ermanent&(
(ress:
0&((ress1
'ermanent'2one:
0'2one1
)irt2(ate: Date
Se3: {4"*}
Class: {*"So"5"Se"%}
4a6orDepartment
4inorDepartment
De7ree: {)&")S"$}
compute87pa
a((8ma6or
(rop8ma6or
a((8minor
(rop8minor
DE'&RT4ENT
Name: {CS"$}
DepartmentCo(e: {Co(es}
O99iceNumber
O99ice'2one:
0'2one1
Colle7e: {Colle7es}
a((8course
(elete8course
2ire89acult:
9ire89acult:
INSTRUCTOR
Name:
0Name1
'2one:
0'2one1
DepartmentCo(e
assi7n87ra(e
c2an7e87ra(e
,8
Chapter 7: Data Modeling Using the Entity-Relationship (ER) Model
$his one isnLt finished yet* $he relationships need to &e added and some of the fun(tions
should &e mo.ed to span (lasses*
Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
,:

S-ar putea să vă placă și