Title | E RModel - The Entity Relationship Model (ERM) The Entity Relationship Model is a representation |
---|---|
Author | Fanelo Felicity |
Course | Informatics |
Institution | University of Pretoria |
Pages | 13 |
File Size | 220 KB |
File Type | |
Total Downloads | 58 |
Total Views | 148 |
The Entity Relationship Model (ERM)
The Entity Relationship Model is a representation of the
conceptual database as viewed from the end user perspective.
The various notations used are the Chen notation and the
Crow’s Foot and the UML notations.
Entities:
An entit...
TheEntityRelationshipModel(ERM) TheEntityRelationshipModelisarepresentationofthe conceptualdatabaseasviewedfromtheenduserperspective. ThevariousnotationsusedaretheChennotationandthe Crow’sFootandtheUMLnotations. Entities: Anentityisanobjectofinteresttotheenduser.Anentity correspondstoatable.Inallnotations,anentityis representedbyarectanglethatcontainstheentity’sname writtenincapitalletters. Attributes: Attributesarecharacteristicsofentitiesandareusually representedasfieldsofthetablesattheimplementationlevel. IntheChenmodel,attributesarerepresentedasovals,each containingthenameoftheattributeitrepresents.Inthe Crow’sFootnotation,theattributesarewrittenintheattribute boxbelowtheentityrectangle.
ChenModel
Crow’sFootModel STUDENT
STU‐INITIAL STU‐LNAME
STU‐EMAIL
STU‐LNAME STUDENT
STU‐FNAME
STU‐PHONE
STU‐FNAME STU‐INITIAL STU‐EMAIL STU‐PHONE
RequiredandOptionalAttributes: Arequiredattributeisanattributethatmusthaveavalue,and itcannotbeleftempty.Thetwoboldfacedattributesinthe Crow’sFootnotationindicatethatthedataentryisrequired. Anoptionalattributeisanattributethatdoesnotrequirea value,itcanbeleftempty. Domains: Adomainisthesetofpossiblevaluesforagivenattribute. Attributemayshareadomain.Thesameattributenameisused fordifferententities,andthentheysharethesamedomain.
IdentifiersorPrimarykeys: InERM,anidentifierisoneormoreattributesthatuniquely identifyeachinstanceortuple.Intherelationalmodel,entities aremappedtotablesandtheentityidentifierismappedasthe table’sprimarykey(PK).Identifiersandprimarykeysare underlinedintheERD. Keyattributesarealsounderlinedintherelationalschema: TABLE_NAME(KEY_ATTRIBUTE1,ATTRIBUTE2,……,ATTRIBUTEK) CompositeIdentifiers: Ideally,anentityidentifierisonlycomposedofonlyasingle attribute.However,itispossibletohaveacompositeidentifier, whichisaprimarykeythatiscomposedofmorethanone attribute. CompositeandSimpleAttributes: Attributesareclassifiedassimpleorcomposite.Acomposite attributeisanattributethatcanbefurthersubdividedtoyield additionalattributes.Forexample,theattribute PHONE_NUMBERcanbesubdividedintoareacodeand exchangenumber. Single_valuedattribute: Asingle‐valuedattributeisanattributethatcanhaveonlya singlevalue.Forexample,apersoncanhaveonlyoneSSN.
Asinglevaluedattributeisnotnecessarilyasimpleattribute. Forinstance,apart’sserialnumbersuchasSE‐08‐02‐16745is single‐valuedbutisacompositeattributethatcanbedivided intotheproductionregionSE,theplantwithintheregion:08, theshift:02andthepartnumber. Multi‐valuedAttributes: Multi‐valuedattributesareattributesthatcanhavemany values.Forexample,apersonmayhaveseveralcollegedegrees ,andahouseholdmayhaveseveralphonenumbers.Inthe ChenERM,multivaluedattributesareshownbyadoubleline connectingtheattributetotheentity.TheCrow’sFoot notationdoesnotidentifymultivaluedattributes.
CARYEAR CARLICENSE
CAR_VIN
CAR
CARMAKE CARCOLOR
ImplementingMulti‐valuedAttributes: Althoughconceptually,themodelcanhandleM:Nrelationships andmutivaluedattributes,theycannotbeimplementedinthe
RDBMS.So,ifmultivaluedattributesexist,thedesignermust decidetwopossiblecourseofaction: 1. Withintheoriginalentity,createseveralnewattributes, oneforeachcomponentoftheoriginalmutivalued attribute.Forexample,theCARentity’sattribute CAR_COLORcanbesplittocreatenewattributes CAR_TOPCOLOR,CAR_BODYCOLORandCAR_TRIMCOLOR whicharethenassignedtotheCARentity.Theproblem withthisapproachisthatiftherearemanyoptionsfor sometuplesandnotforalltuples,thenthevaluesfor mostofthenewattributesisgoingtobeNULL. 2. Createanewentitycomposedbytheoriginalmultivalued attribute’scomponents.Thenewentityallowsthe designertodefinedifferentvaluesfortheattribute.Doing itthisway,allowsustodefineasmanycolorsforthecar asneededwithouthavingtochangethetablestructure. Thisisthepreferredwaytodealwithmultivalued attributes.Creatinganewentityina1:Mrelationshipwith theoriginalentityyieldsseveralbenefits:itismore flexible,expandablesolution,anditiscompatiblewiththe relationalmodel.
DerivedAttributes: Aderivedattributeoracomputedattributeisanattribute whosevalueiscalculated(derived)fromotherattributes. Thederivedattributeneednotbephysicallystoredinthe database. Relationships: Arelationshipisanassociationbetweenentities.The entitiesthatparticipateinarelationshiparealsocalled participants.Arelationshipbetweenentitiesalways operatesinbothdirections.Todefinetherelationship betweentheentitiesname,entityrelationshipsmaybe classifiedasone‐to‐one,one‐to‐many,ormany‐to‐many. ConnectivityandCardinality: Cardinalityexpressestheminimumandmaximum numberoftuplesassociatedwithonetupleoftherelated entity.IntheERDcardinalityisindicatedbyplacingthe appropriatenumberbesidestheentities,usingtheformat (x,y).Thefirstvaluerepresentstheminimumnumberof associatedtuples,whilethesecondvaluerepresentsthe maximumnumberofassociatedtuples.
PROFESSOR
teaches
(1:1)(1,4)
CLASS
(1:4)meansthateachprofessorteachesupto4classes.This meansthataPROFESSOR’tupleprimarykeyoccursatleast onceandatmostfourtimesasaforeignkeyvaluesinthe CLASStable. (1:1)indicatesthateachclassistaughtbyoneandonlyone professor.ThatiseachtuplefromtheCLASStableisassociated withoneandonlyonetuplefromthePROFESSOR’stable. ExistenceDependence: Anentityissaidtobeexistence‐dependentifitcanexistinthe databaseonlywhenitisassociatedwithanotherrelatedentity. Inimplementationterms,anentityisexistence‐dependentifit hasamandatoryforeignkey,whichcannotbeNULL.Example: anemployeedependentsentitycanonlyexistsifthereisa tupleforaspecificemployeeintheEMPLOYEEtable. StrongEntities:Ifanentitycanexistapartfromallitsrelated entities,thenitisexistence‐independentanditisreferredtoas strongentityorregularentity. RelationshipStrengths:(StrongRelationships)
Theconceptofrelationshipstrengthisrelatedonhowprimary keys(PK)aredefinedamongentities.Toimplementa relationship,theprimarykeyofoneentity(theparententity, normallyonthe“one”sideoftheone‐to‐manyrelationship) appearsasaforeignkey(FK)intherelatedentity(the“many” sideontheone‐to‐manyrelationship).Sometimes,theforeign keyisalsoaprimarykeyintherelatedentity. WeakorNon_identifyingRelationships: Aweakrelationshipexistsiftheprimarykeyoftherelated entitydoesnotcontainaprimarykeycomponentoftheparent entity.Bydefault,relationshipsareestablishedbyhavingthe primarykeyoftheparententityappearasaforeignkeyonthe relatedentity(childentity) Example,supposewehavea1:MrelationshipbetweenCOURSE andCLASSas: COURSE(CRS_CODE,DEPT_CODE,CRS_DESCRIPTION,CRS_CREDIT) CLASS(CLASS_CODE,CRS_CODE,CLASS‐SECTION,CLASS_TIME, ROOM_CODE,PROF_NUM)
Inthiscase,aweakrelationshipexistsbetweenCOURSEand CLASS,becausethePKofCOURSEisaFKforCLASS.
IntheCROWnotation,aweakrelationshipisrepresentedby placingadashedrelationshiplinebetweenentities
COURSE PK
CLASS
CRS_CODE DEPT_CODE
CLASS_CODE
FK1
CRS_CODE
generates CRS_DESCRIPTION
PK
CLASS_SECTION
CRS_CREDIT
CLASS_TIME
ROOM_CODE
PROF_NUM
Strong(Identifying)Relationships: Astrongrelationshipexistswhentheprimarykeyoftherelated entitycontainsaprimarykeycomponentoftheparententity. Forexample,supposethe1:MrelationshipbetweenCLASSand COURSEisdefinedas: COURSE(CRS_CODE,DEPT_CODE,CRS_DESCRIPTION,CRS_CREDIT) CLASS(CRS_CODE,CLASS_CODE,CLASS‐SECTION,CLASS_TIME, ROOM_CODE,PROF_NUM)
Inthiscase,theCLASSentityprimarykeyiscomposedof CRS_CODEandCLASS_SECTION.Therefore,astrong relationshipexistsbetweenCOURSEandCLASS. WeakEntities: Incontrasttostrongorregularentitiesmentionedearlier,a weakentityisonethatmeetstwoconditions: 1. Theentityisexistence‐dependent,itcannotexistwithout theentitywithwhichithasarelationship. 2. Theentityhasaprimarykeythatispartiallyortotally derivedfromtheparententityintherelationship. Forexample,acompanyinsurancepolicymaycoveran employeeandtheirdependents.AnEMPLOYEEmayormay nothaveanyDEPENDANTS,howeveraDEPENDENTmustbe associatedwithanEMPLOYEEandiftheEMPLOYEEis deletedthentheDEPENDENTisalsodeleted.DEPENDENTis aweakentityintherelationship“EMPLOYEEhas DEPENDENT”. RelationshipParticipation: Participationinarelationshipiseitheroptionalor mandatory. Optionalparticipation:meansthatoneentityoccurrence doesnotrequireacorrespondingentityoccurrenceinthe
relationship.Forexample,anEMPLOYEEmayhaveno DEPENDENT.ThereforetheDEPENDENTentityisoptionalfor theEMPLOYEEentity.TheCrow’sFootnotation,anoptional relationshipisshownbydrawingasmallcircle(O)ontheside oftheoptionalentity.Thecorrespondingminimalcardinality is0. Mandatoryparticipation:meansthatoneentityoccurrence requiresacorrespondingentityrecurrenceinaparticular relationship.Ifnooptionalitysymbolisdepicted,the relationshipisassumedtobemandatory.Theexistenceofa mandatoryparticipationimpliesaconnectivityof1anda minimumcardinalityof1. Relationshipdegrees: Arelationshipdegreeindicatesthenumberofentitiesor participantsassociatedwiththerelationship. Aunaryrelationshipexistswhenanassociationismaintained withinasingleentity.Forexample:anemployeewithinthe EMPLOYEEentityisthemanagerofoneormoreemployees withintheentity.Inthiscase,the"manages"relationship meansthatEMPLOYEErequiresthatanotherEMPLOYEEbe themanagerthatisEMPLOYEEhasarelationshipwithitself.
Thisisknownasarecursiverelationship.Recursive relationshipsarerepresentedlike: manages EMPLOYEE Abinaryrelationshiprequirestwoentitiestoberelated. Thesearethemostcommontypeofrelationshipsand usuallyhigherorderrelationshipsaredecomposedinto appropriateequivalentbinaryrelationships. Aternaryrelationshipexistswhenthreeentitiesarerelated. Although,theyarerare,theyaresometimesnecessary.A ternaryrelationshipimpliesanassociationamongthree differententities.Example: • ADOCTORwritesoneormorePRESCRPTIONS • APATIENTmayreceiveoneormorePRESCRIPTIONS • ADRUGmayappearinoneormorePRESCRIPTIONS.
Adoctorcanbescheduledformanyappointments,but maynothaveanyscheduledatall.Eachappointmentis scheduledwithexactly1doctor.Apatientcanschedule1 ormoreappointments.Oneappointmentisscheduled withexactly1patient. Anappointmentmustgenerateexactly1bill,abillis generatedbyonly1appointment.Onepaymentisapplied toexactly1bill,and1billcanbepaidoffovertimeby severalpayments.Abillcanbeoutstanding,having nothingyetpaidonitatall.Onepatientcanmakemany payments,butasinglepaymentismadebyonly1patient. Somepatientsareinsuredbyaninsurancecompany.If theyareinsured,theycanonlycarryinsurancewithone company.Aninsurancecompanycanhavemanypatients carrytheirpolicies.Forpatientsthatcarryinsurance,the insurancecompanywillmakepayments,eachsingle paymentismadebyexactly1insurancecompany. ...