Академический Документы
Профессиональный Документы
Культура Документы
13
14
ERModel
TheERmodelisnotintendedtobe
associatedwithanyparticulardatabase
model.
ERdiagramsareintendedtoallowhumans
theabilitytocapturemoreofthe
applicationsmeaning.
15
16
HistoryofERModel
ERModelwasproposed
byDr.PeterChen
(currentlyprofessorat
LouisianaStateUniversity)
ChensoriginalpaperonE
RModelisthe35thmost
sitedpaperincomputer
science
Chenhaswrittenpapers
interconnectingERmodel
andlinguistics
17
TheEntityRelationshipModel
(History)
DevelopedbyPeterCheninthe1970s
Severalvariationshaveevolved
Allaredesignedtowardstheconcise
captureoftheapplicationsemanticsin
termsappropriateforsubsequentmapping
toaspecificdatabasemodel.
Itiscurrentlythemostwidelyused.
18
19
TheEntityRelationshipApproach
Entity:anobjectthatexistsandis
distinguishablefromotherobjects.i.e.
person,place,thing,eventorconceptabout
whichinformation(attributes)isrecorded.
ThebasicunitoftheERmodel.
Thestructureofanentityiscalledits
schema.
110
MoreTerminology
Object:thingsintherealworldthatcanbe
observedandclassifiedbecausetheyhave
relatedproperties
Entity:thegroupingsweusewhenwe
categorizetheobjects.Sometimescalleda
class.
111
112
113
ThreeBasicGraphicalSymbolsinan
ERDiagram
Rectanglesareusedtomodelconceptual
dataunitsordataobjects.
Circlesareusedtomodelattributes. Course
Attributesarethecharacteristics,
componentsorpropertiesofentities.
CID
Diamondsareusedtomodelthestructural
associationsthatexistbetweenentities.
Enroll
114
115
116
BASICCONCEPTS
Thereare3basicnotionsintheERModel:
EntitySets
RelationshipSets
Attributes
117
ANENTITY
Anentityisathingorobjectintherealworldthat
isdistinguishablefromallotherobjects.Ithasan
uniquesetofpropertiesthatmayuniquelyidentifyan
entity.Forexample,astudententityhasthree
attributes:name,studentid,andsocialsecurity
numbers.
John 1222 123122244
STUDENT entity
118
ENTITYSETS
Anentitysetisasetofentitiesthatsharethesame
propertiesorattributes.Entitysetsdonotneedtobe
disjoint.Forexample,acustomercanalsobean
employee.
John
Kathy
Steve
1222
2223
3222
123122244
223222245
723122244
John
Kathy
Steve
Manager
Teller
Teller
ATTRIBUTE
Anentityisrepresentedbyasetofattributes.
Attributesaredescriptivepropertiespossessedbyeach
memberofanentityset.
Example:
STUDENT entity
STUDENT
Attributes
name
student-id
address
ss#
120
ATTRIBUTETYPES
Thereareseveraldifferenttypesofattributes.
SimpleandComposite
SinglevaluedandMultivalued
Derived
Null
121
ATTRIBUTETYPES
Simpleattributesarenotdividedintosubparts.
Compositeattributescanbedividedintosubparts.
Usingcompositeattributesinadesignschemaisa
goodchoiceifauserwillwishtorefertoanentire
attributeonsomeoccasions.
122
ATTRIBUTETYPES
Example:
address(Compositeattribute)
Composite
street
city
state
zip
attribute
streetnumber
streetname
apartmentnumber
123
ATTRIBUTETYPES
Singlevaluedattributesareattributesthatonlyhaveasingle
valueforaparticularentity.
Multivaluedattributesreferstoentitiesthatarenotsingled
valueandNullvalued.Forexample,consideranemployee
entitysetwiththeattributephonenumber.Anemployeemay
havezero,one,orseveralphonenumbers,differentemployee
mayhavedifferentnumbersofphones.
124
ATTRIBUTETYPES
Nullattributeisusedwhenanentitydoesnothaveavalue
foranattribute.
Derivedattributesrefertoanattributethatcanbederived
fromotherrelatedattributesorentities.Forinstance,suppose
thatAgeandDateofbirthareattributesoftheCUSTOMER
entityset.WecancalculateAgefromDateofbirth.Inthis
case,Ageisaderivedattribute.
125
RELATIONSHIPSETS
Arelationshipisanassociationamongseveralentities.
Arelationshipsetisasetofrelationshipsofthesametype.Consider
thetwoentitysetscustomerandloan.Wedefinetherelationshipset
borrowertodenotetheassociationbetweencustomersandbankloans
thatthecustomershave.
321123123
Jones
Main
Harrison
L17
1000
019283746
Smith
North
Rye
L23
2000
555555555
Jackson Dupont
Woodside
L14
1500
321123123
Curry
North
Rye
L19
500
321123123
Adam
Spring
Pittsfield
L16
1300
customer
loan
126
RECURSIVERELATIONSHIP
Recursiverelationshipthesameentitysetparticipatesinarelationship
setmorethanonce,indifferentroles.Thefunctionthatanentityplaysin
arelationshipiscalledthatentitysrole.Forexample,consideranentity
setemployeethatrecordsinformationaboutallemployeesofthebank.
Wemayhavearelationshipsetworksforthatismodeledbyordered
pairsofemployeeentities.Thefirstemployeeofapairtakestheroleof
worker,whereasthesecondtakestheroleofmanager.
employee-name
telephone-number
employee-id
manager
employee
worker
Recursive Relationship
works-for
127
BINARYRELATIONSHIP
SETS
Binaryrelationshipsetrelationshipthatinvolves
twoidentitysets.
Mostoftherelationshipsetsinadatabasesystemare
binary.Occasionally,however,relationshipset
involvemorethantwoentity.
OWNER
Owns
PROPERTY-FOR-RENT
128
TERNARYRELATIONSHIP
SET
Ternaryrelationshipsetrelationshipthatinvolves
threeidentitysets
DEGREE
earned
PERSON
Ternary Relationship
Set
129
DEGREEOFA
RELATIONSHIPSET
Degreeofarelationshipsetisthenumberofentity
setsthatparticipateinarelationshipset.Forexample,
abinaryrelationshipsetisofdegree2;aternary
relationshipsetisofdegree3.
130
CONSTRAINTS
AnERenterpriseschememaydefinecertainconstraintsto
whichthecontentsofadatabasemustconform.Thetwoof
mostimportanttypesofconstraintsareMappingCardinalities
andParticipationConstraints.
ParticipationConstraints
TheparticipationofanentitysetEinarelationshipsetRis
saidtobetotal,ifeveryentityinEparticipatesinatleastone
relationshipinR.IfonlysomeentitiesinEparticipatein
relationshipR,theparticipationofentitysetEinrelationship
Rissaidtobepartial.
131
CONSTRAINTS
MappingCardinalitiesorCardinalityratios
Expressthenumberofentitiestowhichanotherentitycanbe
associatedviaarelationshipset
Aremostusefulindescribingbinaryrelationshipsets.Fora
binaryrelationshipsetRbetweenentitysetsAandB,the
mappingcardinalitymustbeoneofthefollowing:
Onetoone
Onetomany
Manytoone
Manytomany
132
MAPPINGCARDINALITIES
Onetoone
AnentityinAisassociatedwithatmostoneentityin
B,andanentityinBisassociatedwithatmostone
entityinA.
A1
B1
A2
B2
A3
B3
133
MAPPINGCARDINALITIES
Onetomany
AnentityinAisassociatedwithanynumber(zeroormore)of
entitiesinB.AnentityinB,however,canbeassociatedwith
atmostoneentityinA.
A2
B1
B2
B3
A3
B4
A1
134
MAPPINGCARDINALITIES
Manytoone
AnentityinAisassociatedwithatmostoneentityinB.An
entityinB,however,canbeassociatedwithanynumber(zero
ormore)ofentitiesinA.
A1
A1
A2
A3
B1
B2
B3
135
MAPPINGCARDINALITIES
Manytomany
AnentityinAisassociatedwithanynumber(zeroormore)of
entitiesinB,andanentityinBisassociatedwithanynumber
(zeroormore)ofentitiesinA.
A1
A1
A2
A3
B1
B2
B3
136
KEYS
Akeyallowsustoidentifyasetofattributesthat
sufficetodistinguishentitiesfromeachother.Keys
alsohelpuniquelyidentifyrelationships,andthus
distinguishrelationshipsfromeachother.Thereare
threetypesofkeys:
Superkey
Candidatekey
Primarykey
137
KEY
Superkeyisasetofoneormoreattributesthat,takencollectively,us
toidentifyuniquelyanentityintheentityset.Forexample,customerid
isasuperkey.
Candidatekeyisaminimalsuperkey.Forexample,customername
andcustomerstreetissufficienttodistinguishamongmembersofthe
customerentityset.Then{customername,customerstreet}isa
candidatekey.
Primarykeydenotesacandidatekeythatischosenbythedatabase
designerastheprincipalmeansofidentifyingentitieswithinanentity
set.theprimarykeyshouldbechosensuchthatitsattributesarenever,
orveryrarely,changed.Forexample,Socialsecuritynumbersare
guaranteedtoneverchanged.
138
RELATIONSHIPSETS
Primarykeyofanentitysetallowsustodistinguish
amongentitiesoftheset.Similarmechanismis
neededinordertodistinguishamongthevarious
relationshipsofarelationshipset.
Thestructureoftheprimarykeyfortherelationship
setdependsonthemappingcardinalityofthe
relationshipset.
139
RELATIONSHIPSETS
Forexample,supposethatthereisarelationshipset
Depositor,withattributeaccessdate,between
CustomerrelationandAccountrelation.Supposethat
therelationshipsetismanytomany.Thenthe
primarykeyofDepositorconsistsoftheunionofthe
primarykeysofCustomerandAccount.Ifacustomer
canhaveonlyoneaccountthatis,iftheDepositor
relationismanytoonefromCustomertoAccount
thentheprimarykeyoftheDepositorrelationshipis
simplytheprimarykeyofcustomer.
140
RELATIONSHIPSETS
Customer(ss#,name)
Account(accountnum)
Depositor(ss#,accountnum,accessdate)
John
Kathy
Steve
123122244
223222245
723122244
Customer
10 May 2002
24 May 2002
A101
A215
3 June 2002
20 June 2002
21 June 2002
Depositor
A102
Account
141
DESIGNISSUE
UseofEntitySetsversusAttributes
Considertheentitysetemployeewithattributesemployee
nameandtelephonenumber.
Treatingatelephoneasanattributetelephonenumber
impliesthatemployeeshavepreciselyonetelephonenumber
each.
Treatingatelephoneasanentitytelephonepermits
employeestohaveseveraltelephonenumber(includingzero)
associatedwiththem.However,wecouldinsteadeasily
definetelephonenumberasamultivaluedattributetoallow
multipletelephonesperemployee.
142
USEOFENTITYSETS
VERSUSATTRIBUTES
Treatingatelephoneasanattribute
John
4083455366
Kathy
4082223455
Steve
7145556366
Treatingatelephoneasanentity
John
4088883565
cellphone
Kathy
4083455366
videophone
Steve
4082223455
cellphone
Alex
7145556366
cellphone
EMPLOYEE (employee-name)
TELEPHONE(telephone-number, type)
143
ENTITYRELATIONSHIP
DIAGRAM
Ellipses,whichrepresentattributes
Diamonds,whichrepresentrelationshipsets
Line,whichlinkattributestoentitysetsandentitysetsto
relationshipssets
Doubleellipses,whichrepresentmultivaluedattributes
Doublelines,whichindicatetotalparticipationofanentity
inarelationshipset
Doublerectangles,whichrepresentweakentitysets
144
Exampleofthe3elementsinE/R
Diagram
145
ClassificationofConstraints
1.
2.
3.
4.
Keys
Singlevalueconstraints
Multivaluedconstraints
MappingCardinalitiesandParticipation
Constraints
146
KeyintheE/RModel
Superkeyisasetofoneormoreattributesthat,takencollectively,for
ustoidentifyuniquelyanitemintheentityset.Forexample,
customeridisasuperkey.
Candidatekeyisaminimalsuperkey.Forexample,customername
andcustomerstreetissufficienttodistinguishamongmembersofthe
customerentityset.Then{customername,customerstreet}isa
candidatekey.
Primarykeydenotesacandidatekeythatischosenbythedatabase
designerastheprincipalmeansofidentifyingitemswithinanentity
set.theprimarykeyshouldbechosensuchthatitsattributesare
never,orveryrarely,changed.Forexample,Socialsecuritynumbers
areguaranteedtoneverchanged.
147
Single/Multivaluedattributes
Singlevaluedattributesareattributesthatonly
haveasinglevalueforaparticularentity.
Multivaluedattributesreferstoitemsthatarenot
singledvalueandNullvalued.Forexample,
consideranemployeeentitysetwiththeattribute
phonenumber.Anemployeemayhavezero,one,
orseveralphonenumbers;differentemployeemay
havedifferentnumbersofphones.
148
149
MappingCardinalitiesorCardinality
ratios
Expressthenumberofitemstowhichanotheritemcanbe
associatedviaarelationshipset
Aremostusefulindescribingbinaryrelationshipsets.For
abinaryrelationshipsetRbetweenentitysetsAandB,the
mappingcardinalitymustbeoneofthefollowing:
OnetoOne
OnetoMany
ManytoOne
ManytoMany
150
ParticipationConstraints
TheparticipationofanentitysetEina
relationshipsetRissaidtobetotal,ifevery
iteminEparticipatesinatleastone
relationshipinR.IfonlysomeitemsinE
participateinrelationshipR,the
participationofentitysetEinrelationship
Rissaidtobepartial.
151
WeakEntitySets
Thereisanoccasionalconditioninwhich
anentitysetskeyiscomposedofattributes
someorallofwhichbelongtoanother
entityset.Suchanentitysetiscalleda
weakentityset.
152
Discriminator
Thediscriminatorofaweakentitysetisasetof
attributesthatallowsthisdistinctiontobemade.
Forexample,thediscriminatorofaweakentityset
paymentistheattributepaymentnumber,since,
foreachloanapaymentnumberuniquely
identifiesonesinglepaymentforthatloan.The
discriminatorofaweakentitysetisalsocalledthe
partialkeyoftheentityset.
153
RequirementsforWeakEntitySets
Wecannotobtainkeyattributesforaweakentity
setindiscriminately.Rather,ifEisaweakentity
setthenitskeyconsistsof:
Zeroormoreofitsownattributes,and
Keyattributesfromentitysetsthatarereachedby
certainmanyonerelationshipfromEtootherentity
sets.Thesemanyonerelationshiparecalled
supportingrelationshipsforE.
154
Discriminator(cont.)
Note:althougheachpaymententityisdistinct,
paymentsfordifferentloansmaysharethesame
paymentnumber.Thus,paymententitysetdoes
nothaveaprimarykey;itisaweakentityset.
Theprimarykeyofaweakentitysetisformedby
theprimarykeyoftheidentifyingentityset,plus
theweakentitysetsdiscriminator.
155
IdentifyingaWeakEntityType
AWeakentitytypedoesnthaveaprimarykey.
IfXisaweakentitytypeandYistheentitytypeon
whichXisdependent.
WeformaprimarykeyforXbycombiningtheprimary
keyofYwhichoneormoreattributes,called
discriminatororpartialkey,fromX.
InanE/RDiagram,apartialkeyisusuallydash
underlined.
e.g.,primarykeyforDEPENDENT:{EmployeeNo.,
DName}.
156
*Dotedline=doubleline
157
DetailedConceptualDesign
Employee
Emp No
Emp Name
First Name
Mid Initials
Last Name
NID
Address
Salary
Gender
DOB
Emp No
Emp Name
Employee
NID
Address
Salary
DOB
Gender
Mid Initials
Last Name
First Name
Emp No
NID
Mid Initials
Emp Name
Last Name
Address
supervise
Gender
works
Start d
DOB
Dependent
works on
Depd Name
Gender
Relation
Dept No
Department
manage
Hours
has
Dept Name
Phone
Employee
Salary
Location
Employees
control
Proj No
Project
DOB
Location
Proj Name
ConceptualDesignwithWeak
Entities
supervise
works
Department
Employee
manage
has
Dependent
works on
control
Project