Elmasri 6e_ISM 07

Embed Size (px)

Citation preview

  • 7/22/2019 Elmasri 6e_ISM 07

    1/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 transripts* $his is similar &ut not idential to the data&ase shown in

    +igure ,*:

    (a) $he uni.ersity 'eeps tra' of eah students name/ student num&er/ soial seuritynum&er/ urrent address and phone/ permanent address and phone/ &irthdate/ se0/ lass(freshman/ sophomore/ ***/ graduate)/ ma1or department/ minor department (if any)/ anddegree program (2*3*/ 2*#*/ ***/ 4h*D*)* #ome user appliations need to refer to the ity/state/ and 5ip of the students permanent address/ and to the students last name* 2othsoial seurity num&er and student num&er ha.e unique .alues for eah student*

    (&) Eah department is desri&ed &y a name/ department ode/ offie num&er/ offie phone/and ollege* 2oth name and ode ha.e unique .alues for eah department*

    () Eah ourse has a ourse name/ desription/ ourse num&er/ num&er of semester hours/le.el/ and offering department* $he .alue of ourse num&er is unique for eah ourse*

    (d) Eah setion has an instrutor/ semester/ year/ ourse/ and setion num&er* $he setionnum&er distinguishes different setions of the same ourse that are taught during the samesemester6year its .alues are ,/ / 8/ ***/ up to the num&er of setions taught during eahsemester*

    (e) 3 grade report has a student/ setion/ letter grade/ and numeri grade (9/ ,/ / 8/ for +/ D/ C/ 2/ 3/ respeti.ely)*

    Design an ER shema for this appliation/ and draw an ER diagram for that shema*#peify 'ey attri&utes of eah entity type and strutural onstraints on eah relationship type*

    ote any unspeified requirements/ and ma'e appropriate assumptions to ma'e thespeifiation omplete*

    Answer:

    Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.

    ,

  • 7/22/2019 Elmasri 6e_ISM 07

    2/14

    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.iousollege eduation* #uh an attri&ute will ha.e one entry for eah ollege pre.iously attended/and this entry is omposed of: ollege name/ start and end dates/ degree entries (degreesawarded at that ollege/ if any)/ and transript entries (ourses ompleted at that ollege/ ifany)* Eah degree entry is formed of degree name and the month and year it was awarded/and eah transript entry is formed of a ourse name/ semester/ year/ and grade* Design anattri&ute to hold this information* Use the on.entions of +igure 7*;*

    Answer:

    < 4re.iousEduation ( Collegeame/ #tartDate/ EndDate/< Degree (Degreeame/ Month/ %ear) =/< $ransript (Courseame/ #emester/ %ear/ >rade) = ) =

    Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.

    7$%&

  • 7/22/2019 Elmasri 6e_ISM 07

    3/14

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

    '$%- #how an alternati.e design for the attri&ute desri&ed in E0erise 7*,7 that uses onlyentity types (inluding wea' entity types if needed) and relationship types*

    Answer:

    $his e0ample illustrates a perei.ed wea'ness of the ER model/ whih is: how does thedata&ase designer deide what to model as an entity type and what to model as arelationship type* !n our solution/ we reated a wea' entity type 3$$ED3CE eah (wea')entity in 3$$ED3CE represents a period in whih a #$UDE$ attended a partiularC?@@E>E/ and is identified &y the #$UDE$ and the #tartDate of the period* Aene/ the#tartDate attri&ute is the partial 'ey of 3$$ED3CE* Eah 3$$ED3CE entity is relatedto one C?@@E>E and 5ero or more DE>REEs (the degrees awarded during that attendaneperiod)* $he $R3#CR!4$ of the #$UDE$ during eah attendane period is modeled as awea' entity type/ whih gi.es the reords of the student during the attendane period* Eah

    (wea') entity in $R3#CR!4$ gi.es the reord of the sudent in one ourse during theattendane period/ as shown in the ER diagram &elow* ?ther ER shema designs are alsopossi&le for this pro&lem*

    Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.

    8

    7$%&

  • 7/22/2019 Elmasri 6e_ISM 07

    4/14

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

    7$%- Consider the ER diagram of +igure 7*9/ whih shows a simplified shema for anairline reser.ations system* E0trat from the ER diagram the requirements and onstraintsthat resulted in this shema* $ry to &e as preise as possi&le in your requirements andonstraints speifiation*

    Answer:

    (,) $he data&ase represents eah 3!R4?R$/ 'eeping its unique 3irportCode/ the 3!R4?R$ame/ and the City and #tate in whih the 3!R4?R$ is loated*

    () Eah airline +@!>A$ has a unique num&er/ the 3irline for the +@!>A$/ and the Bee'dayson whih the +@!>A$ is sheduled (for e0ample/ e.ery day of the wee' e0ept #unday an&e oded as 7)*

    (8) 3 +@!>A$ is omposed of one or more +@!>A$ @E>s (for e0ample/ flight num&erC?,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)* Eah +@!>A$ @E> has a DE43R$URE

    3!R4?R$ and #heduled Departure $ime/ and an 3RR!"3@ 3!R4?R$ and #heduled3rri.al $ime*

    () 3 @E> !#$3CE is an instane of a +@!>A$ @E> on a speifi Date (for e0ample/C?,8 leg , on uly 89/ ,F)* $he atual Departure and 3rri.al 3!R4?R$s and$imes are reorded for eah flight leg after the flight leg has &een onluded* $heum&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 eah @E> !#$3CE inlude the Customer ame/4hone/ and #eat um&er(s) for eah reser.ation*

    Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.

  • 7/22/2019 Elmasri 6e_ISM 07

    5/14

    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 eah 3!R4@3E$%4E (for e0ample/ DC-,9)/ the $ypeame/ manufaturing Company/ andMa0imum um&er of #eats are 'ept* $he 3!R4?R$s in whih planes of this typeC3 @3D are 'ept in the data&ase* +or eah 3!R4@3E/ the 3irplane!d/ $otal num&er ofseats/ 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 onstruted to 'eep tra' of the teams and games of a sportsleague* 3 team has a num&er of players/ not all of whom partiipate in eah game*!t is desired to 'eep tra' of the players partiipating in eah game for eah team/ thepositions they played in that game/ and the result of the game* $ry to design an ER shemadiagram for this appliation/ stating any assumptions you ma'e* Choose your fa.orite sport(soer/ foot&all/ &ase&all ***)*

    Answer:

    $he following design may &e used for a &ase&all league* Aere/ we assumed that eah gamein the shedule is identified &y a unique >ameI/ and a game is also identified uniquely &ythe om&ination of Date/ starting $ime/ and +ield where it is played* $he 4erformane

    Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.

    ;

  • 7/22/2019 Elmasri 6e_ISM 07

    6/14

    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 performane of eahplayer in a game* $his attri&ute an &e designed to 'eep the information needed forstatistis/ and may &e quite omple0* ?ne possi&le design for the 4erformane attri&ute may&e the following (using the notation of +igure 7*F):

    4erformane(

  • 7/22/2019 Elmasri 6e_ISM 07

    7/14

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

    (d) @ist the names of all relationship types/ and speify the (min/ma0) onstraint on eahpartiipation of an entity type in a relationship type* ustify your hoies*

    (e) @ist onisely the user requirements that led to this ER shema design*

    (f) #uppose that e.ery ustomer must ha.e at least one aount &ut is restritedto at most two loans at a time/ and that a &an' &ranh 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: 2ranho*!dentifying relationship: 2R3CAE#*

    () $he partial 'ey 2ranho in 23H-2R3CA speifies that the same 2ranho .alue ayour under different 23Hs* $he identifying relationship 2R3CAE# speifies that

    Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.

    7

  • 7/22/2019 Elmasri 6e_ISM 07

    8/14

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

    2ranho .alues are uniquely assigned for those 23H-2R3CA entities that are relatedto the same 23H entity* Aene/ the om&ination of 23H Code and 2ranho togetheronstitute a full identifier for a 23H-2R3CA*

    (d) Relationship $ypes: 2R3CAE#/ 3CC$#/ @?3#/ 3-C/ @-C* $he (min/ ma0) onstraintsare shown &elow*

    (e) $he requirements may &e stated as follows: Eah 23H has a unique Code/ as well as aame and 3ddress* Eah 23H is related to one or more 23H-2R3CAes/ and the2ranho is unique among eah set of 23H-2R3CAes that are related to the same 23H*Eah 23H-2R3CA has an 3ddress* Eah 23H-2R3CA has 5ero or more @?3# and5ero or more 3CC$#* Eah 3CC?U$ has an 3to (unique)/ 2alane/ and $ype and isrelated to e0atly one 23H-2R3CA and to at least one CU#$?MER* Eah @?3 has a@oano (unique)/ 3mount/ and $ype and is related to e0atly one 23H-2R3CA and to atleast one CU#$?MER* Eah 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 totwo departments or may not &e assigned to any department* 3ssume that eah departmentmust ha.e one and may ha.e up to three phone num&ers* #upply (min/ ma0) onstraints onthis diagram* #tate learly any additional assumptions you ma'e* Under what onditionswould the relationship A3#K4A?E &e redundant in this e0ampleJ

    Answer:

    3ssuming the following additional assumptions:- Eah department an ha.e anywhere &etween , and ,9 employees*- Eah phone is used &y one/ and only one/ department*

    - Eah phone is assigned to at least one/ and may &e assigned to up to ,9 employees*- Eah 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:- Eah employee is assigned all of the phones of eah department that he6she wor's in*

    Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.

    F

  • 7/22/2019 Elmasri 6e_ISM 07

    9/14

    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@?%EE4A?EDE43R$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 ate0t&oo'/ &ut that a te0t &y definition is a &oo' that is used in some ourse* 3 ourse may notuse more than fi.e &oo's* !nstrutors teah from two to four ourses* #upply (min/ ma0)onstraints on this diagram* #tate learly any additional assumptions you ma'e* !f we addthe relationship 3D?4$# &etween !#$RUC$?R and $E$/ what (min/ ma0) onstraintswould you put on itJ BhyJ

    Answer:

    3ssuming the following additional assumptions:- Eah ourse is taught &y e0atly one instrutor*- Eah te0t&oo' is used &y one and only one ourse*- 3n instrutor does not ha.e to adopt a te0t&oo' for all ourses*- !f a te0t e0ists:- KKKit is used in some ourse/- KKKhene it is adopted &y some instrutor who teahes that ourse*- 3n instrutor is onsidered to adopt a te0t if it is used in some ourse taught- &y that instrutor*

    $he resulting ER Diagram will ha.e the (min/ ma0) onstraints shown in +igure 2*

    7$*&- Consider an entity type SECTIONin a UNIVERSITYdata&ase/ whih desri&es the

    setion offerings of ourses* $he attri&utes of SECTION are #etionum&er/ #emester/

    %ear/ Courseum&er/ !nstrutor/ Roomo (where setion is taught)/ 2uilding (where setionis taught)/ Bee'days (domain is the possi&le om&inations of wee'days in whih a setionan &e offered

  • 7/22/2019 Elmasri 6e_ISM 07

    10/14

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

    within a partiular semester6year om&ination (that is/ if a ourse if offered multiple timesduring a partiular semester/ its setion offerings are num&ered ,/ / 8/ et*)* $here arese.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 shemadiagram*

    Answer:

    7$*7- Cardinality ratios often ditate the detailed design of a data&ase* $he ardinality ratiodepends on the real-world meaning of the entity types in.ol.ed and is defined &y the speifiappliation* +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 #oial#eurityCard

    * #tudent $eaher

    8* ClassRoom Ball

    * Country Current4resident

    ;* Course $e0t2oo'

    G*!tem (that an &efound in an order)

    ?rder

    Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.

    ,9

  • 7/22/2019 Elmasri 6e_ISM 07

    11/14

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

    7* #tudent Class

    F* Class !nstrutor

    * !nstrutor ?ffie

    ,9*E-&ay 3utionitem

    E-&ay &id

    Answer:

    Entity , Cardinality Ratio Entity

    ,* #tudent

    ,-many

    3 student may ha.e morethan one soial seurityard (legally with thesame unique soialseurity num&er)/ ande.ery soial seuritynum&er &elongs to aunique student*

    #oial#eurityCard

    * #tudent

    Many-many

    >enerally students aretaught &y many teahersand a teaher teahesmany students*

    $eaher

    8* ClassRoom

    Many-many

    DonLt forget that the wallis usually shared &yad1aent rooms*

    Ball

    * Country

    ,-,

    3ssuming a normalountry under normal

    irumstanes ha.ing onepresident at a time*

    Current4resident

    ;* Course

    Many-many

    3 ourse may ha.e manyte0t&oo's and a te0t &oo'may &e presri&ed fordifferent ourses*

    $e0t2oo'

    Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.

    ,,

  • 7/22/2019 Elmasri 6e_ISM 07

    12/14

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

    G*!tem (that an &efound in an order)

    Many-many

    3ssuming the same iteman appear in differentorders*

    ?rder

    7* #tudent

    Many-many

    ?ne student may ta'ese.eral lasses* E.erylass usually has se.eralstudents*

    Class

    F* Class

    Many-to-,

    3ssuming that e.ery lasshas a unique instrutor* !nase instrutors wereallowed to team teah/this will &e many-many*

    !nstrutor

    * !nstrutor

    ,-,

    3ssuming e.ery instrutorhas only one offie and itis not shared* !n ase ofoffies shared &y instrutors/ therelationship will &e -,*Con.ersely/ if aninstrutor has a 1oint

    appointment (in twodepartments) and offiesin &oth departments/ thenthe relationship will &e ,-* !n a .ery general ase/it may &e many-many*

    ?ffie

    ,9*E-&ay 3utionitem

    ,-many

    , item has many &ids anda &id is unique to an item(assuming a regularaution format)*

    E-&ay &id

    7$*-7$* o solutions pro.ided*

    '$'+- !llustrate the UM@ Diagram for e0erise 7*,G* %our UM@ design should o&ser.e thefollowing requirements:

    a* $he student should ha.e the a&ility to ompute his6her >43 and add or drop ma1orsand minors*

    Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.

    ,

  • 7/22/2019 Elmasri 6e_ISM 07

    13/14

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

    &* Eah department should &e to a&le add or delete ourses and hire or terminatefaulty*

    * Eah instrutor should &e a&le to assign or hange a grade to a student for a ourse*

    Note:#ome of these funtions may &e spread o.er multiple lasses*

    Answer:

    Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.

    COURSE

    CourseName

    DescriptionCourseNumber: {Course}

    SemesterHoursLevelDepartment

    SECTION

    InstructorSemester

    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:

    0Name1Stu(entNumber

    SocialSecNumber

    Current&((ress:

    0&((ress1Current'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

    (rop8ma6ora((8minor

    (rop8minor

    DE'&RT4ENT

    Name: {CS"$}

    DepartmentCo(e: {Co(es}O99iceNumber

    O99ice'2one:

    0'2one1

    Colle7e: {Colle7es}

    a((8course

    (elete8course

    2ire89acult9ire89acult

    INSTRUCTOR

    Name:

    0Name1'2one:

    0'2one1

    DepartmentCo(e

    assi7n87ra(e

    c2an7e87ra(e

    ,8

  • 7/22/2019 Elmasri 6e_ISM 07

    14/14

    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 funtionsshould &e mo.ed to span lasses*

    Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.

    ,