Professional Documents
Culture Documents
DatabaseSystemConcepts,5thEd.
Silberschatz,KorthandSudarshan Seewww.dbbook.comforconditionsonreuse
Chapter6:EntityRelationshipModel
s DesignProcess s Modeling s Constraints s ERDiagram s DesignIssues s WeakEntitySets s ExtendedERFeatures s DesignoftheBankDatabase s ReductiontoRelationSchemas s DatabaseDesign s UML
DatabaseSystemConcepts5thEdition,July11,2005
6.<number>
Silberschatz,KorthandSudarshan
Modeling
s Adatabasecanbemodeledas:
q q
acollectionofentities, relationshipamongentities.
s Anentityisanobjectthatexistsandisdistinguishablefromother
objects.
q
Example:specificperson,company,event,plant
Example:peoplehavenamesandaddresses
s Entitieshaveattributes
q
s Anentitysetisasetofentitiesofthesametypethatsharethesame
properties.
q
Example:setofallpersons,companies,trees,holidays
DatabaseSystemConcepts5thEdition,July11,2005
6.<number>
Silberschatz,KorthandSudarshan
EntitySetscustomerandloan
customer_idcustomer_customer_customer_loan_amount namestreetcitynumber
DatabaseSystemConcepts5thEdition,July11,2005
6.<number>
Silberschatz,KorthandSudarshan
RelationshipSets
s Arelationshipisanassociationamongseveralentities
depositor relationshipset
A102 accountentity
s Arelationshipsetisamathematicalrelationamongn2entities,each
{(e1,e2,en)|e1E1,e2E2,,enEn} where(e1,e2,,en)isarelationship
q
Example: (Hayes,A102)depositor
DatabaseSystemConcepts5thEdition,July11,2005
6.<number>
Silberschatz,KorthandSudarshan
RelationshipSetborrower
DatabaseSystemConcepts5thEdition,July11,2005
6.<number>
Silberschatz,KorthandSudarshan
RelationshipSets(Cont.)
s Anattributecanalsobepropertyofarelationshipset. s Forinstance,thedepositorrelationshipsetbetweenentitysetscustomer
andaccountmayhavetheattributeaccessdate
DatabaseSystemConcepts5thEdition,July11,2005
6.<number>
Silberschatz,KorthandSudarshan
DegreeofaRelationshipSet
s Referstonumberofentitysetsthatparticipateinarelationship
set.
s Relationshipsetsthatinvolvetwoentitysetsarebinary(or
degreetwo).Generally,mostrelationshipsetsinadatabase systemarebinary.
s Relationshipsetsmayinvolvemorethantwoentitysets.
relationshipsarebinary.(Moreonthislater.)
DatabaseSystemConcepts5thEdition,July11,2005
6.<number>
Silberschatz,KorthandSudarshan
Attributes
s Anentityisrepresentedbyasetofattributes,thatisdescriptive
propertiespossessedbyallmembersofanentityset.
Example:
Simpleandcompositeattributes. Singlevaluedandmultivaluedattributes
Derivedattributes
DatabaseSystemConcepts5thEdition,July11,2005
CompositeAttributes
DatabaseSystemConcepts5thEdition,July11,2005
6.<number>
Silberschatz,KorthandSudarshan
MappingCardinalityConstraints
s Expressthenumberofentitiestowhichanotherentitycanbe
associatedviaarelationshipset.
s Mostusefulindescribingbinaryrelationshipsets. s Forabinaryrelationshipsetthemappingcardinalitymustbeoneof
thefollowingtypes:
q q q q
DatabaseSystemConcepts5thEdition,July11,2005
6.<number>
Silberschatz,KorthandSudarshan
MappingCardinalities
Note:SomeelementsinAandBmaynotbemappedtoany elementsintheotherset
DatabaseSystemConcepts5thEdition,July11,2005 6.<number> Silberschatz,KorthandSudarshan
Onetoone
Onetomany
MappingCardinalities
Manytoone
Manytomany
Note:SomeelementsinAandBmaynotbemappedtoany elementsintheotherset
DatabaseSystemConcepts5thEdition,July11,2005 6.<number> Silberschatz,KorthandSudarshan
Keys
s Asuperkeyofanentitysetisasetofoneormoreattributes
whosevaluesuniquelydetermineeachentity.
q q
s Acandidatekeyofanentitysetisaminimalsuperkey
Customer_idiscandidatekeyofcustomer account_numberiscandidatekeyofaccount
s Althoughseveralcandidatekeysmayexist,oneofthecandidate
keysisselectedtobetheprimarykey.
DatabaseSystemConcepts5thEdition,July11,2005
6.<number>
Silberschatz,KorthandSudarshan
KeysforRelationshipSets
s Thecombinationofprimarykeysoftheparticipatingentitysetsformsa
superkeyofarelationshipset.
q q
s Mustconsiderthemappingcardinalityoftherelationshipsetwhen
decidingwhatarethecandidatekeys
s Needtoconsidersemanticsofrelationshipsetinselectingtheprimary
keyincaseofmorethanonecandidatekey
DatabaseSystemConcepts5thEdition,July11,2005
6.<number>
Silberschatz,KorthandSudarshan
ERDiagrams
Doubleellipsesrepresentmultivaluedattributes. Dashedellipsesdenotederivedattributes.
s Underlineindicatesprimarykeyattributes(willstudylater)
DatabaseSystemConcepts5thEdition,July11,2005
6.<number>
Silberschatz,KorthandSudarshan
ERDiagramWithComposite,Multivalued,and DerivedAttributes
DatabaseSystemConcepts5thEdition,July11,2005
6.<number>
Silberschatz,KorthandSudarshan
RelationshipSetswithAttributes
DatabaseSystemConcepts5thEdition,July11,2005
6.<number>
Silberschatz,KorthandSudarshan
Roles
s Entitysetsofarelationshipneednotbedistinct s Thelabelsmanagerandworkerarecalledroles;theyspecifyhow
s RolesareindicatedinERdiagramsbylabelingthelinesthatconnect s Rolelabelsareoptional,andareusedtoclarifysemanticsofthe
DatabaseSystemConcepts5thEdition,July11,2005
6.<number>
Silberschatz,KorthandSudarshan
CardinalityConstraints
s Weexpresscardinalityconstraintsbydrawingeitheradirectedline(),
signifyingone,oranundirectedline(),signifyingmany,between therelationshipsetandtheentityset.
q
s Onetoonerelationship:
DatabaseSystemConcepts5thEdition,July11,2005
6.<number>
Silberschatz,KorthandSudarshan
OneToManyRelationship
s Intheonetomanyrelationshipaloanisassociatedwithatmostone
customerviaborrower,acustomerisassociatedwithseveral(including 0)loansviaborrower
DatabaseSystemConcepts5thEdition,July11,2005
6.<number>
Silberschatz,KorthandSudarshan
ManyToOneRelationships
s Inamanytoonerelationshipaloanisassociatedwithseveral(including
0)customersviaborrower,acustomerisassociatedwithatmostone loanviaborrower
DatabaseSystemConcepts5thEdition,July11,2005
6.<number>
Silberschatz,KorthandSudarshan
ManyToManyRelationship
s Acustomerisassociatedwithseveral(possibly0)loansvia
borrower borrower
s Aloanisassociatedwithseveral(possibly0)customersvia
DatabaseSystemConcepts5thEdition,July11,2005
6.<number>
Silberschatz,KorthandSudarshan
ParticipationofanEntitySetina RelationshipSet
s Totalparticipation(indicatedbydoubleline):everyentityintheentityset
participatesinatleastonerelationshipintherelationshipset
q
E.g.participationofloaninborroweristotal
everyloanmusthaveacustomerassociatedtoitviaborrower
s Partialparticipation:someentitiesmaynotparticipateinanyrelationshipin
therelationshipset
q
Example:participationofcustomerinborrowerispartial
DatabaseSystemConcepts5thEdition,July11,2005
6.<number>
Silberschatz,KorthandSudarshan
AlternativeNotationforCardinalityLimits
s Cardinalitylimitscanalsoexpressparticipationconstraints
DatabaseSystemConcepts5thEdition,July11,2005
6.<number>
Silberschatz,KorthandSudarshan
ERDiagramwithaTernaryRelationship
DatabaseSystemConcepts5thEdition,July11,2005
6.<number>
Silberschatz,KorthandSudarshan
CardinalityConstraintsonTernary Relationship
s Weallowatmostonearrowoutofaternary(orgreaterdegree)relationship
toindicateacardinalityconstraint mostonejobatanybranch.
q
s E.g.anarrowfromworks_ontojobindicateseachemployeeworksonat s Ifthereismorethanonearrow,therearetwowaysofdefiningthemeaning.
q q
Eachalternativehasbeenusedindifferentformalisms Toavoidconfusionweoutlawmorethanonearrow
DatabaseSystemConcepts5thEdition,July11,2005
6.<number>
Silberschatz,KorthandSudarshan
DesignIssues
s Useofentitysetsvs.attributes
s Useofentitysetsvs.relationshipsets
s Binaryversusnaryrelationshipsets
s Placementofrelationshipattributes
DatabaseSystemConcepts5thEdition,July11,2005
6.<number>
Silberschatz,KorthandSudarshan
BinaryVs.NonBinaryRelationships
s Somerelationshipsthatappeartobenonbinarymaybebetter
representedusingbinaryrelationships
q
Buttherearesomerelationshipsthatarenaturallynonbinary
DatabaseSystemConcepts5thEdition,July11,2005
6.<number>
Silberschatz,KorthandSudarshan
ConvertingNonBinaryRelationshipsto BinaryForm
s
Ingeneral,anynonbinaryrelationshipcanberepresentedusingbinaryrelationships bycreatinganartificialentityset.
q
q q q
1.anewentityeiintheentitysetE2.add(ei,ai)toRA 3.add(ei,bi)toRB
DatabaseSystemConcepts5thEdition,July11,2005
6.<number>
Silberschatz,KorthandSudarshan
ConvertingNonBinaryRelationships (Cont.)
s Alsoneedtotranslateconstraints
q q
DatabaseSystemConcepts5thEdition,July11,2005
6.<number>
Silberschatz,KorthandSudarshan
MappingCardinalitiesaffectERDesign
s Canmakeaccessdateanattributeofaccount,insteadofarelationship
attribute,ifeachaccountcanhaveonlyonecustomer
q
Thatis,therelationshipfromaccounttocustomerismanytoone,or equivalently,customertoaccountisonetomany
DatabaseSystemConcepts5thEdition,July11,2005
6.<number>
Silberschatz,KorthandSudarshan
DatabaseSystemConcepts,5thEd.
Silberschatz,KorthandSudarshan Seewww.dbbook.comforconditionsonreuse
WeakEntitySets
s Anentitysetthatdoesnothaveaprimarykeyisreferredtoasaweak
entityset.
s Theexistenceofaweakentitysetdependsontheexistenceofa
identifyingentityset
q
s Thediscriminator(orpartialkey)ofaweakentitysetisthesetof
s Theprimarykeyofaweakentitysetisformedbytheprimarykeyofthe
DatabaseSystemConcepts5thEdition,July11,2005
6.<number>
Silberschatz,KorthandSudarshan
WeakEntitySets(Cont.)
s Wedepictaweakentitysetbydoublerectangles. s Weunderlinethediscriminatorofaweakentitysetwithadashed
line.
s payment_numberdiscriminatorofthepaymententityset s Primarykeyforpayment(loan_number,payment_number)
DatabaseSystemConcepts5thEdition,July11,2005
6.<number>
Silberschatz,KorthandSudarshan
WeakEntitySets(Cont.)
s Note:theprimarykeyofthestrongentitysetisnotexplicitlystored
withtheweakentityset,sinceitisimplicitintheidentifying relationship.
s Ifloan_numberwereexplicitlystored,paymentcouldbemadea
DatabaseSystemConcepts5thEdition,July11,2005
6.<number>
Silberschatz,KorthandSudarshan
MoreWeakEntitySetExamples
s Inauniversity,acourseisastrongentityandacourse_offeringcan
bemodeledasaweakentity
s Thediscriminatorofcourse_offeringwouldbesemester(including
year)andsection_number(ifthereismorethanonesection) course_numberasanattribute.
s Ifwemodelcourse_offeringasastrongentitywewouldmodel
Thentherelationshipwithcoursewouldbeimplicitinthe course_numberattribute
DatabaseSystemConcepts5thEdition,July11,2005
6.<number>
Silberschatz,KorthandSudarshan
ExtendedERFeatures:Specialization
s Topdowndesignprocess;wedesignatesubgroupingswithinanentityset
thataredistinctivefromotherentitiesintheset.
s Thesesubgroupingsbecomelowerlevelentitysetsthathaveattributesor
participateinrelationshipsthatdonotapplytothehigherlevelentityset. person).
s DepictedbyatrianglecomponentlabeledISA(E.g.customerisa s Attributeinheritancealowerlevelentitysetinheritsalltheattributes
andrelationshipparticipationofthehigherlevelentitysettowhichitis linked.
DatabaseSystemConcepts5thEdition,July11,2005
6.<number>
Silberschatz,KorthandSudarshan
SpecializationExample
DatabaseSystemConcepts5thEdition,July11,2005
6.<number>
Silberschatz,KorthandSudarshan
ExtendedERFeatures:Generalization
s Abottomupdesignprocesscombineanumberofentitysets
thatsharethesamefeaturesintoahigherlevelentityset.
s Specializationandgeneralizationaresimpleinversionsofeach s Thetermsspecializationandgeneralizationareused
other;theyarerepresentedinanERdiagraminthesameway. interchangeably.
DatabaseSystemConcepts5thEdition,July11,2005
6.<number>
Silberschatz,KorthandSudarshan
SpecializationandGeneralization(Cont.)
s Canhavemultiplespecializationsofanentitysetbasedondifferent
features.
s E.g.permanent_employeevs.temporary_employee,inadditionto
officervs.secretaryvs.teller
q q
s Eachparticularemployeewouldbe
amemberofoneofpermanent_employeeortemporary_employee, andalsoamemberofoneofofficer,secretary,orteller
s TheISArelationshipalsoreferredtoassuperclasssubclass
relationship
DatabaseSystemConcepts5thEdition,July11,2005
6.<number>
Silberschatz,KorthandSudarshan
DesignConstraintsona Specialization/Generalization
s Constraintonwhichentitiescanbemembersofagivenlowerlevel
entityset.
q
userdefined
s Constraintonwhetherornotentitiesmaybelongtomorethanone
lowerlevelentitysetwithinasinglegeneralization.
q
Disjoint
Overlapping
DatabaseSystemConcepts5thEdition,July11,2005
6.<number>
Silberschatz,KorthandSudarshan
DesignConstraintsona Specialization/Generalization(Cont.)
s Completenessconstraintspecifieswhetherornotanentity
inthehigherlevelentitysetmustbelongtoatleastoneofthe lowerlevelentitysetswithinageneralization.
q
DatabaseSystemConcepts5thEdition,July11,2005
6.<number>
Silberschatz,KorthandSudarshan
Aggregation
sConsidertheternaryrelationshipworks_on,whichwesawearlier sSupposewewanttorecordmanagersfortasksperformedbyan
employeeatabranch
DatabaseSystemConcepts5thEdition,July11,2005
6.<number>
Silberschatz,KorthandSudarshan
Aggregation(Cont.)
s Relationshipsetsworks_onandmanagesrepresentoverlappinginformation
q q
Sowecantdiscardtheworks_onrelationship
s Eliminatethisredundancyviaaggregation
q q q
s Withoutintroducingredundancy,thefollowingdiagramrepresents:
q q
DatabaseSystemConcepts5thEdition,July11,2005
6.<number>
Silberschatz,KorthandSudarshan
ERDiagramWithAggregation
DatabaseSystemConcepts5thEdition,July11,2005
6.<number>
Silberschatz,KorthandSudarshan
ERDesignDecisions
s Theuseofanattributeorentitysettorepresentanobject. s Whetherarealworldconceptisbestexpressedbyanentitysetor
arelationshipset. relationships.
inthedesign.
s Theuseofaggregationcantreattheaggregateentitysetasa
singleunitwithoutconcernforthedetailsofitsinternalstructure.
DatabaseSystemConcepts5thEdition,July11,2005
6.<number>
Silberschatz,KorthandSudarshan
ERDiagramforaBankingEnterprise
DatabaseSystemConcepts5thEdition,July11,2005
6.<number>
Silberschatz,KorthandSudarshan
HowaboutdoinganotherERdesign interactivelyontheboard?
DatabaseSystemConcepts,5thEd.
Silberschatz,KorthandSudarshan Seewww.dbbook.comforconditionsonreuse
SummaryofSymbolsUsedinERNotation
DatabaseSystemConcepts5thEdition,July11,2005
6.<number>
Silberschatz,KorthandSudarshan
SummaryofSymbols(Cont.)
DatabaseSystemConcepts5thEdition,July11,2005
6.<number>
Silberschatz,KorthandSudarshan
ReductiontoRelationSchemas
s Primarykeysallowentitysetsandrelationshipsetstobe
s AdatabasewhichconformstoanERdiagramcanbe s Foreachentitysetandrelationshipsetthereisaunique
s Eachschemahasanumberofcolumns(generally
DatabaseSystemConcepts5thEdition,July11,2005
6.<number>
Silberschatz,KorthandSudarshan
RepresentingEntitySetsasSchemas
s Astrongentitysetreducestoaschemawiththesameattributes. s Aweakentitysetbecomesatablethatincludesacolumnforthe
primarykeyoftheidentifyingstrongentityset payment=
(loan_number,payment_number,payment_date,payment_amount)
DatabaseSystemConcepts5thEdition,July11,2005
6.<number>
Silberschatz,KorthandSudarshan
RepresentingRelationshipSetsas Schemas
s Amanytomanyrelationshipsetisrepresentedasaschemawith
s Example:schemaforrelationshipsetborrower
DatabaseSystemConcepts5thEdition,July11,2005
6.<number>
Silberschatz,KorthandSudarshan
RedundancyofSchemas
s Manytooneandonetomanyrelationshipsetsthataretotalonthe
s Example:Insteadofcreatingaschemaforrelationshipset
DatabaseSystemConcepts5thEdition,July11,2005
6.<number>
Silberschatz,KorthandSudarshan
RedundancyofSchemas(Cont.)
s Foronetoonerelationshipsets,eithersidecanbechosentoactasthe
manyside
q
Thatis,extraattributecanbeaddedtoeitherofthetables correspondingtothetwoentitysets
s Ifparticipationispartialonthemanyside,replacingaschemabyan
s Theschemacorrespondingtoarelationshipsetlinkingaweakentityset
DatabaseSystemConcepts5thEdition,July11,2005
6.<number>
Silberschatz,KorthandSudarshan
CompositeandMultivaluedAttributes
s Compositeattributesareflattenedoutbycreatingaseparateattributefor
eachcomponentattribute
q
s AmultivaluedattributeMofanentityEisrepresentedbyaseparate
schemaEM
q
DatabaseSystemConcepts5thEdition,July11,2005
RepresentingSpecializationvia Schemas
s Method1:
q q
Formaschemaforthehigherlevelentity Formaschemaforeachlowerlevelentityset,includeprimary keyofhigherlevelentitysetandlocalattributes schema person customer employee attributes name,street,city name,credit_rating name,salary
DatabaseSystemConcepts5thEdition,July11,2005
6.<number>
Silberschatz,KorthandSudarshan
RepresentingSpecializationasSchemas (Cont.)
s Method2:
q
Ifspecializationistotal,theschemaforthegeneralizedentityset (person)notrequiredtostoreinformation
Drawback:streetandcitymaybestoredredundantlyforpeoplewhoare bothcustomersandemployees
DatabaseSystemConcepts5thEdition,July11,2005
6.<number>
Silberschatz,KorthandSudarshan
SchemasCorrespondingtoAggregation
s Torepresentaggregation,createaschemacontaining
q q q
DatabaseSystemConcepts5thEdition,July11,2005
6.<number>
Silberschatz,KorthandSudarshan
SchemasCorrespondingto Aggregation(Cont.)
s Forexample,torepresentaggregationmanagesbetween
relationshipworks_onandentitysetmanager,createaschema manages(employee_id,branch_name,title,manager_name)
s Schemaworks_onisredundantprovidedwearewillingtostorenull
valuesforattributemanager_nameinrelationonschemamanages
DatabaseSystemConcepts5thEdition,July11,2005
6.<number>
Silberschatz,KorthandSudarshan
UML
s UML:UnifiedModelingLanguage s UMLhasmanycomponentstographicallymodeldifferentaspectsofan
entiresoftwaresystem differences.
s UMLClassDiagramscorrespondtoERDiagram,butseveral
DatabaseSystemConcepts5thEdition,July11,2005
6.<number>
Silberschatz,KorthandSudarshan
SummaryofUMLClassDiagramNotation
DatabaseSystemConcepts5thEdition,July11,2005
6.<number>
Silberschatz,KorthandSudarshan
UMLClassDiagrams(Cont.)
s Entitysetsareshownasboxes,andattributesareshownwithinthe
box,ratherthanasseparateellipsesinERdiagrams.
s BinaryrelationshipsetsarerepresentedinUMLbyjustdrawingaline
s Theroleplayedbyanentitysetinarelationshipsetmayalsobe
s Therelationshipsetnamemayalternativelybewritteninabox,along
s Nonbinaryrelationshipsdrawnusingdiamonds,justasinER
DatabaseSystemConcepts5thEdition,July11,2005
6.<number>
Silberschatz,KorthandSudarshan
UMLClassDiagramNotation(Cont.)
overlapping
disjoint
UMLClassDiagrams(Contd.)
s Cardinalityconstraintsarespecifiedintheforml..h,wherel
s Beware:thepositioningoftheconstraintsisexactlythereverse s Theconstraint0..*ontheE2sideand0..1ontheE1sidemeans
s Singlevalues,suchas1or*maybewrittenonedges;The
singlevalue1onanedgeistreatedasequivalentto1..1,while* isequivalentto0..*.
DatabaseSystemConcepts5thEdition,July11,2005
6.<number>
Silberschatz,KorthandSudarshan
EndofChapter2
DatabaseSystemConcepts,5thEd.
Silberschatz,KorthandSudarshan Seewww.dbbook.comforconditionsonreuse
ERDiagramforExercise2.10
DatabaseSystemConcepts5thEdition,July11,2005
6.<number>
Silberschatz,KorthandSudarshan
ERDiagramforExercise2.15
DatabaseSystemConcepts5thEdition,July11,2005
6.<number>
Silberschatz,KorthandSudarshan
ERDiagramforExercise2.22
DatabaseSystemConcepts5thEdition,July11,2005
6.<number>
Silberschatz,KorthandSudarshan
ERDiagramforExercise2.15
DatabaseSystemConcepts5thEdition,July11,2005
6.<number>
Silberschatz,KorthandSudarshan
ExistenceDependencies
s Iftheexistenceofentityxdependsontheexistenceofentityy,
thenxissaidtobeexistencedependentony.
q q
yisadominantentity(inexamplebelow,loan) xisasubordinateentity(inexamplebelow,payment)
loan
loanpayment
payment
Ifaloanentityisdeleted,thenallitsassociatedpaymententities mustbedeletedalso.
DatabaseSystemConcepts5thEdition,July11,2005
6.<number>
Silberschatz,KorthandSudarshan
Figure6.8
DatabaseSystemConcepts5thEdition,July11,2005
6.<number>
Silberschatz,KorthandSudarshan
Figure6.15
DatabaseSystemConcepts5thEdition,July11,2005
6.<number>
Silberschatz,KorthandSudarshan
Figure6.16
DatabaseSystemConcepts5thEdition,July11,2005
6.<number>
Silberschatz,KorthandSudarshan
Figure6.26
DatabaseSystemConcepts5thEdition,July11,2005
6.<number>
Silberschatz,KorthandSudarshan
Figure6.27
DatabaseSystemConcepts5thEdition,July11,2005
6.<number>
Silberschatz,KorthandSudarshan
Figure6.28
DatabaseSystemConcepts5thEdition,July11,2005
6.<number>
Silberschatz,KorthandSudarshan
Figure6.29
DatabaseSystemConcepts5thEdition,July11,2005
6.<number>
Silberschatz,KorthandSudarshan
Figure6.30
DatabaseSystemConcepts5thEdition,July11,2005
6.<number>
Silberschatz,KorthandSudarshan
Figure6.31
DatabaseSystemConcepts5thEdition,July11,2005
6.<number>
Silberschatz,KorthandSudarshan
AlternativeERNotations Figure6.24
DatabaseSystemConcepts5thEdition,July11,2005
6.<number>
Silberschatz,KorthandSudarshan