You are on page 1of 82

Chapter6:EntityRelationshipModel

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

Example: Hayes customerentity takenfromentitysets

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.

Example:Supposeemployeesofabankmayhavejobs (responsibilities)atmultiplebranches,withdifferentjobsat differentbranches.Thenthereisaternaryrelationshipset betweenentitysetsemployee,job,andbranch


s Relationshipsbetweenmorethantwoentitysetsarerare.Most

relationshipsarebinary.(Moreonthislater.)

DatabaseSystemConcepts5thEdition,July11,2005

6.<number>

Silberschatz,KorthandSudarshan

Attributes
s Anentityisrepresentedbyasetofattributes,thatisdescriptive

propertiespossessedbyallmembersofanentityset.

Example:

customer=(customer_id,customer_name, customer_street,customer_city) loan=(loan_number,amount)


s Domainthesetofpermittedvaluesforeachattribute s Attributetypes:
q q

Simpleandcompositeattributes. Singlevaluedandmultivaluedattributes

Example:multivaluedattribute:phone_numbers Canbecomputedfromotherattributes Example:age,givendate_of_birth


6.<number> Silberschatz,KorthandSudarshan

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

Onetoone Onetomany Manytoone Manytomany

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

(customer_id,account_number)isthesuperkeyofdepositor NOTE:thismeansapairofentitysetscanhaveatmostone relationshipinaparticularrelationshipset.

Example:ifwewishtotrackallaccess_datestoeachaccountby eachcustomer,wecannotassumearelationshipforeach access.Wecanuseamultivaluedattributethough

s Mustconsiderthemappingcardinalityoftherelationshipsetwhen

decidingwhatarethecandidatekeys

s Needtoconsidersemanticsofrelationshipsetinselectingtheprimary

keyincaseofmorethanonecandidatekey

DatabaseSystemConcepts5thEdition,July11,2005

6.<number>

Silberschatz,KorthandSudarshan

ERDiagrams

s Rectanglesrepresententitysets. s Diamondsrepresentrelationshipsets. s Lineslinkattributestoentitysetsandentitysetstorelationshipsets. s Ellipsesrepresentattributes


q q

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

employeeentitiesinteractviatheworks_forrelationshipset. diamondstorectangles. relationship

s RolesareindicatedinERdiagramsbylabelingthelinesthatconnect s Rolelabelsareoptional,andareusedtoclarifysemanticsofthe

DatabaseSystemConcepts5thEdition,July11,2005

6.<number>

Silberschatz,KorthandSudarshan

CardinalityConstraints
s Weexpresscardinalityconstraintsbydrawingeitheradirectedline(),

signifyingone,oranundirectedline(),signifyingmany,between therelationshipsetandtheentityset.
q

s Onetoonerelationship:

Acustomerisassociatedwithatmostoneloanviatherelationship borrower Aloanisassociatedwithatmostonecustomerviaborrower

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.

E.gaternaryrelationshipRbetweenA,BandCwitharrowstoBandC couldmean 1.eachAentityisassociatedwithauniqueentityfromBandCor 2.eachpairofentitiesfrom(A,B)isassociatedwithauniqueCentity, andeachpair(A,C)isassociatedwithauniqueB

q q

Eachalternativehasbeenusedindifferentformalisms Toavoidconfusionweoutlawmorethanonearrow

DatabaseSystemConcepts5thEdition,July11,2005

6.<number>

Silberschatz,KorthandSudarshan

DesignIssues
s Useofentitysetsvs.attributes

Choicemainlydependsonthestructureoftheenterprisebeing modeled,andonthesemanticsassociatedwiththeattributein question. Possibleguidelineistodesignatearelationshipsettodescribean actionthatoccursbetweenentities Althoughitispossibletoreplaceanynonbinary(nary,forn>2) relationshipsetbyanumberofdistinctbinaryrelationshipsets,a naryrelationshipsetshowsmoreclearlythatseveralentities participateinasinglerelationship.

s Useofentitysetsvs.relationshipsets

s Binaryversusnaryrelationshipsets

s Placementofrelationshipattributes

DatabaseSystemConcepts5thEdition,July11,2005

6.<number>

Silberschatz,KorthandSudarshan

BinaryVs.NonBinaryRelationships
s Somerelationshipsthatappeartobenonbinarymaybebetter

representedusingbinaryrelationships
q

E.g.Aternaryrelationshipparents,relatingachildtohis/herfather andmother,isbestreplacedbytwobinaryrelationships,father andmother

Usingtwobinaryrelationshipsallowspartialinformation(e.g. onlymotherbeingknow) Example:works_on

Buttherearesomerelationshipsthatarenaturallynonbinary

DatabaseSystemConcepts5thEdition,July11,2005

6.<number>

Silberschatz,KorthandSudarshan

ConvertingNonBinaryRelationshipsto BinaryForm
s

Ingeneral,anynonbinaryrelationshipcanberepresentedusingbinaryrelationships bycreatinganartificialentityset.
q

ReplaceRbetweenentitysetsA,BandCbyanentitysetE,andthree relationshipsets: 1.RA,relatingEandA 3.RC,relatingEandC 2.RB,relatingEandB

q q q

CreateaspecialidentifyingattributeforE AddanyattributesofRtoE Foreachrelationship(ai,bi,ci)inR,create 4.add(ei,ci)toRC

1.anewentityeiintheentitysetE2.add(ei,ai)toRA 3.add(ei,bi)toRB

DatabaseSystemConcepts5thEdition,July11,2005

6.<number>

Silberschatz,KorthandSudarshan

ConvertingNonBinaryRelationships (Cont.)
s Alsoneedtotranslateconstraints
q q

Translatingallconstraintsmaynotbepossible Theremaybeinstancesinthetranslatedschemathat cannotcorrespondtoanyinstanceofR

Exercise:addconstraintstotherelationshipsRA,RBand RCtoensurethatanewlycreatedentitycorrespondsto exactlyoneentityineachofentitysetsA,BandC

WecanavoidcreatinganidentifyingattributebymakingEa weakentityset(describedshortly)identifiedbythethree relationshipsets

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

HowaboutdoinganERdesign interactivelyontheboard? Suggestanapplicationtobemodeled.

DatabaseSystemConcepts,5thEd.
Silberschatz,KorthandSudarshan Seewww.dbbook.comforconditionsonreuse

WeakEntitySets
s Anentitysetthatdoesnothaveaprimarykeyisreferredtoasaweak

entityset.

s Theexistenceofaweakentitysetdependsontheexistenceofa

identifyingentityset
q

itmustrelatetotheidentifyingentitysetviaatotal,onetomany relationshipsetfromtheidentifyingtotheweakentityset Identifyingrelationshipdepictedusingadoublediamond

s Thediscriminator(orpartialkey)ofaweakentitysetisthesetof

attributesthatdistinguishesamongalltheentitiesofaweakentityset. strongentitysetonwhichtheweakentitysetisexistencedependent, plustheweakentitysetsdiscriminator.

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

strongentity,butthentherelationshipbetweenpaymentandloan wouldbeduplicatedbyanimplicitrelationshipdefinedbythe attributeloan_numbercommontopaymentandloan

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

conditiondefined Example:allcustomersover65yearsaremembersofsenior citizenentityset;seniorcitizenISAperson.

userdefined

s Constraintonwhetherornotentitiesmaybelongtomorethanone

lowerlevelentitysetwithinasinglegeneralization.
q

Disjoint

anentitycanbelongtoonlyonelowerlevelentityset NotedinERdiagrambywritingdisjointnexttotheISA triangle anentitycanbelongtomorethanonelowerlevelentityset

Overlapping

DatabaseSystemConcepts5thEdition,July11,2005

6.<number>

Silberschatz,KorthandSudarshan

DesignConstraintsona Specialization/Generalization(Cont.)
s Completenessconstraintspecifieswhetherornotanentity

inthehigherlevelentitysetmustbelongtoatleastoneofthe lowerlevelentitysetswithinageneralization.
q

total:anentitymustbelongtooneofthelowerlevelentity sets partial:anentityneednotbelongtooneofthelowerlevel entitysets

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

Everymanagesrelationshipcorrespondstoaworks_onrelationship However,someworks_onrelationshipsmaynotcorrespondtoany managesrelationships

Sowecantdiscardtheworks_onrelationship

s Eliminatethisredundancyviaaggregation
q q q

Treatrelationshipasanabstractentity Allowsrelationshipsbetweenrelationships Abstractionofrelationshipintonewentity Anemployeeworksonaparticularjobataparticularbranch Anemployee,branch,jobcombinationmayhaveanassociatedmanager

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.

s Theuseofaternaryrelationshipversusapairofbinary s Theuseofastrongorweakentityset. s Theuseofspecialization/generalizationcontributestomodularity

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

expresseduniformlyasrelationschemasthatrepresentthe contentsofthedatabase. representedbyacollectionofschemas.

s AdatabasewhichconformstoanERdiagramcanbe s Foreachentitysetandrelationshipsetthereisaunique

schemathatisassignedthenameofthecorrespondingentity setorrelationshipset. correspondingtoattributes),whichhaveuniquenames.

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

attributesfortheprimarykeysofthetwoparticipatingentitysets, andanydescriptiveattributesoftherelationshipset. borrower=(customer_id,loan_number)

s Example:schemaforrelationshipsetborrower

DatabaseSystemConcepts5thEdition,July11,2005

6.<number>

Silberschatz,KorthandSudarshan

RedundancyofSchemas
s Manytooneandonetomanyrelationshipsetsthataretotalonthe

manysidecanberepresentedbyaddinganextraattributetothe manyside,containingtheprimarykeyoftheoneside account_branch,addanattributebranch_nametotheschema arisingfromentitysetaccount

s Example:Insteadofcreatingaschemaforrelationshipset

DatabaseSystemConcepts5thEdition,July11,2005

6.<number>

Silberschatz,KorthandSudarshan

RedundancyofSchemas(Cont.)
s Foronetoonerelationshipsets,eithersidecanbechosentoactasthe

manyside
q

Thatis,extraattributecanbeaddedtoeitherofthetables correspondingtothetwoentitysets

s Ifparticipationispartialonthemanyside,replacingaschemabyan

extraattributeintheschemacorrespondingtothemanysidecould resultinnullvalues toitsidentifyingstrongentitysetisredundant.


q

s Theschemacorrespondingtoarelationshipsetlinkingaweakentityset

Example:Thepaymentschemaalreadycontainstheattributesthat wouldappearintheloan_paymentschema(i.e.,loan_numberand payment_number).

DatabaseSystemConcepts5thEdition,July11,2005

6.<number>

Silberschatz,KorthandSudarshan

CompositeandMultivaluedAttributes
s Compositeattributesareflattenedoutbycreatingaseparateattributefor

eachcomponentattribute
q

Example:givenentitysetcustomerwithcompositeattributenamewith componentattributesfirst_nameandlast_nametheschema correspondingtotheentitysethastwoattributes name.first_nameandname.last_name

s AmultivaluedattributeMofanentityEisrepresentedbyaseparate

schemaEM
q

SchemaEMhasattributescorrespondingtotheprimarykeyofEand anattributecorrespondingtomultivaluedattributeM Example:Multivaluedattributedependent_namesofemployeeis representedbyaschema: employee_dependent_names=(employee_id,dname) Eachvalueofthemultivaluedattributemapstoaseparatetupleofthe relationonschemaEM

Forexample,anemployeeentitywithprimarykey123456789 anddependentsJackandJanemapstotwotuples: (123456789,Jack)and(123456789,Jane)


6.<number> Silberschatz,KorthandSudarshan

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

Drawback:gettinginformationabout,anemployeerequires accessingtworelations,theonecorrespondingtothelowlevel schemaandtheonecorrespondingtothehighlevelschema

DatabaseSystemConcepts5thEdition,July11,2005

6.<number>

Silberschatz,KorthandSudarshan

RepresentingSpecializationasSchemas (Cont.)
s Method2:
q

Formaschemaforeachentitysetwithalllocalandinheritedattributes schema person customer employee attributes name,street,city name,street,city,credit_rating name,street,city,salary

Ifspecializationistotal,theschemaforthegeneralizedentityset (person)notrequiredtostoreinformation

Canbedefinedasaviewrelationcontainingunionofspecialization relations Butexplicitschemamaystillbeneededforforeignkeyconstraints

Drawback:streetandcitymaybestoredredundantlyforpeoplewhoare bothcustomersandemployees

DatabaseSystemConcepts5thEdition,July11,2005

6.<number>

Silberschatz,KorthandSudarshan

SchemasCorrespondingtoAggregation
s Torepresentaggregation,createaschemacontaining
q q q

primarykeyoftheaggregatedrelationship, theprimarykeyoftheassociatedentityset anydescriptiveattributes

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

connectingtheentitysets.Therelationshipsetnameiswrittenadjacent totheline. specifiedbywritingtherolenameontheline,adjacenttotheentityset. withattributesoftherelationshipset,andtheboxisconnected,usinga dottedline,tothelinedepictingtherelationshipset. diagrams

s Theroleplayedbyanentitysetinarelationshipsetmayalsobe

s Therelationshipsetnamemayalternativelybewritteninabox,along

s Nonbinaryrelationshipsdrawnusingdiamonds,justasinER

DatabaseSystemConcepts5thEdition,July11,2005

6.<number>

Silberschatz,KorthandSudarshan

UMLClassDiagramNotation(Cont.)

overlapping

disjoint

*Notereversalofpositionincardinalityconstraintdepiction *Generalizationcanusemergedorseparatearrowsindependent ofdisjoint/overlapping


DatabaseSystemConcepts5thEdition,July11,2005 6.<number> Silberschatz,KorthandSudarshan

UMLClassDiagrams(Contd.)
s Cardinalityconstraintsarespecifiedintheforml..h,wherel

denotestheminimumandhthemaximumnumberof relationshipsanentitycanparticipatein. ofthepositioningofconstraintsinERdiagrams.

s Beware:thepositioningoftheconstraintsisexactlythereverse s Theconstraint0..*ontheE2sideand0..1ontheE1sidemeans

thateachE2entitycanparticipateinatmostonerelationship, whereaseachE1entitycanparticipateinmanyrelationships;in otherwords,therelationshipismanytoonefromE2toE1.

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

You might also like