![Page 1: Modern Database Management 7th Edition, Chapter 3](https://reader034.vdocuments.site/reader034/viewer/2022050800/586cc9521a28ab427c8b7f4d/html5/thumbnails/1.jpg)
©© 2005 by Prentice Hall 2005 by Prentice Hall 11
Modern Database ManagementModern Database Management77thth Edition, Chapter 3 Edition, Chapter 3
Jeffrey A. Hoffer, Mary B. Prescott,Jeffrey A. Hoffer, Mary B. Prescott,Fred R. McFaddenFred R. McFadden
Slides edited by Rasmus PaghSlides edited by Rasmus Pagh
![Page 2: Modern Database Management 7th Edition, Chapter 3](https://reader034.vdocuments.site/reader034/viewer/2022050800/586cc9521a28ab427c8b7f4d/html5/thumbnails/2.jpg)
22Chapter 3 ©© 2005 by Prentice Hall 2005 by Prentice Hall
Simpelt E-R diagramSimpelt E-R diagram
Hvordan ser de tilsvarende relationer ud?
![Page 3: Modern Database Management 7th Edition, Chapter 3](https://reader034.vdocuments.site/reader034/viewer/2022050800/586cc9521a28ab427c8b7f4d/html5/thumbnails/3.jpg)
33Chapter 3 ©© 2005 by Prentice Hall 2005 by Prentice Hall
What Should an Entity Type Be?What Should an Entity Type Be?
SHOULD BE:SHOULD BE: An object that will have many instances inAn object that will have many instances in
the databasethe database An object that will be composed of multipleAn object that will be composed of multiple
attributesattributes An object that we are trying to modelAn object that we are trying to model
SHOULD NOT BE:SHOULD NOT BE: A user of the database systemA user of the database system An output of the database system (e.g. aAn output of the database system (e.g. a
report)report)
![Page 4: Modern Database Management 7th Edition, Chapter 3](https://reader034.vdocuments.site/reader034/viewer/2022050800/586cc9521a28ab427c8b7f4d/html5/thumbnails/4.jpg)
44Chapter 3 ©© 2005 by Prentice Hall 2005 by Prentice Hall
ExamplesExamples
• The actor ”Bruce Willis” should not be an entity type - there isonly one instance.
• ”Middle-aged actors” is not an entity type - could be a query
• Year is not an entity because it does not have multipleattributes (that we want to model, anyway)
• The title of a film is not an entity type, unless we want toassociate more info with each title (like relationships amongmovies with that title)
![Page 5: Modern Database Management 7th Edition, Chapter 3](https://reader034.vdocuments.site/reader034/viewer/2022050800/586cc9521a28ab427c8b7f4d/html5/thumbnails/5.jpg)
55Chapter 3 ©© 2005 by Prentice Hall 2005 by Prentice Hall
Sample E-R Diagram (Figure 3-1)
![Page 6: Modern Database Management 7th Edition, Chapter 3](https://reader034.vdocuments.site/reader034/viewer/2022050800/586cc9521a28ab427c8b7f4d/html5/thumbnails/6.jpg)
66Chapter 3 ©© 2005 by Prentice Hall 2005 by Prentice Hall
![Page 7: Modern Database Management 7th Edition, Chapter 3](https://reader034.vdocuments.site/reader034/viewer/2022050800/586cc9521a28ab427c8b7f4d/html5/thumbnails/7.jpg)
77Chapter 3 ©© 2005 by Prentice Hall 2005 by Prentice Hall
![Page 8: Modern Database Management 7th Edition, Chapter 3](https://reader034.vdocuments.site/reader034/viewer/2022050800/586cc9521a28ab427c8b7f4d/html5/thumbnails/8.jpg)
88Chapter 3 ©© 2005 by Prentice Hall 2005 by Prentice Hall
Basic relationship with only maximum cardinalities – Figure 3-16a
Default minimum is 0, default maximum is 1.
Mandatory minimum cardinalities – Figure 3-17a
![Page 9: Modern Database Management 7th Edition, Chapter 3](https://reader034.vdocuments.site/reader034/viewer/2022050800/586cc9521a28ab427c8b7f4d/html5/thumbnails/9.jpg)
99Chapter 3 ©© 2005 by Prentice Hall 2005 by Prentice Hall
Figure 3-11a A binary relationship with an attribute
Here, the date completed attribute pertains specifically to theemployee’s completion of a course…it is an attribute of therelationship.
NOTE: Only one value for each relationship instance.
![Page 10: Modern Database Management 7th Edition, Chapter 3](https://reader034.vdocuments.site/reader034/viewer/2022050800/586cc9521a28ab427c8b7f4d/html5/thumbnails/10.jpg)
1010Chapter 3 ©© 2005 by Prentice Hall 2005 by Prentice Hall
Problemsession (5-10 min)Problemsession (5-10 min) Vi vil designe en database til en lille butik medVi vil designe en database til en lille butik med
information om kunderne, ordrer og kredit:information om kunderne, ordrer og kredit: Navne og adresserNavne og adresser TelefonnumreTelefonnumre Kundetyper (privat eller forretning)Kundetyper (privat eller forretning) VarerVarer Aktuelle ordrerAktuelle ordrer KundenumreKundenumre Maximum kreditMaximum kredit Aktuel kreditAktuel kredit
Tegn et muligt E-R diagram for databasen.Tegn et muligt E-R diagram for databasen.
![Page 11: Modern Database Management 7th Edition, Chapter 3](https://reader034.vdocuments.site/reader034/viewer/2022050800/586cc9521a28ab427c8b7f4d/html5/thumbnails/11.jpg)
1111Chapter 3 ©© 2005 by Prentice Hall 2005 by Prentice Hall
Figure 3-7 – A composite attribute
An attributebroken intocomponent parts
![Page 12: Modern Database Management 7th Edition, Chapter 3](https://reader034.vdocuments.site/reader034/viewer/2022050800/586cc9521a28ab427c8b7f4d/html5/thumbnails/12.jpg)
1212Chapter 3 ©© 2005 by Prentice Hall 2005 by Prentice Hall
![Page 13: Modern Database Management 7th Edition, Chapter 3](https://reader034.vdocuments.site/reader034/viewer/2022050800/586cc9521a28ab427c8b7f4d/html5/thumbnails/13.jpg)
1313Chapter 3 ©© 2005 by Prentice Hall 2005 by Prentice Hall
Representing a bill-of -materials structure
Figure 3-13a – A unary relationship with an attribute.This has a many-to-many relationship
![Page 14: Modern Database Management 7th Edition, Chapter 3](https://reader034.vdocuments.site/reader034/viewer/2022050800/586cc9521a28ab427c8b7f4d/html5/thumbnails/14.jpg)
1414Chapter 3 ©© 2005 by Prentice Hall 2005 by Prentice Hall
Figure 3-12c -- A ternary relationship (with attributes)
![Page 15: Modern Database Management 7th Edition, Chapter 3](https://reader034.vdocuments.site/reader034/viewer/2022050800/586cc9521a28ab427c8b7f4d/html5/thumbnails/15.jpg)
1515Chapter 3 ©© 2005 by Prentice Hall 2005 by Prentice Hall
![Page 16: Modern Database Management 7th Edition, Chapter 3](https://reader034.vdocuments.site/reader034/viewer/2022050800/586cc9521a28ab427c8b7f4d/html5/thumbnails/16.jpg)
1616Chapter 3 ©© 2005 by Prentice Hall 2005 by Prentice Hall
Entities can be related to one another in more than one way
![Page 17: Modern Database Management 7th Edition, Chapter 3](https://reader034.vdocuments.site/reader034/viewer/2022050800/586cc9521a28ab427c8b7f4d/html5/thumbnails/17.jpg)
1717Chapter 3 ©© 2005 by Prentice Hall 2005 by Prentice Hall
IdentifiersIdentifiers
Candidate Key - An attribute (orCandidate Key - An attribute (orcombination of attributes) that uniquelycombination of attributes) that uniquelyidentifies individual instances of an entityidentifies individual instances of an entitytype.type.
Identifier (or Identifier (or ““KeyKey””) ) –– one particular one particularcandidate key that was chosen to uniquelycandidate key that was chosen to uniquelyidentify entity instances.identify entity instances.
![Page 18: Modern Database Management 7th Edition, Chapter 3](https://reader034.vdocuments.site/reader034/viewer/2022050800/586cc9521a28ab427c8b7f4d/html5/thumbnails/18.jpg)
1818Chapter 3 ©© 2005 by Prentice Hall 2005 by Prentice Hall
Identifier design criteriaIdentifier design criteria
Should not change in valueShould not change in value Should not be nullShould not be null No No ““intelligent identifiersintelligent identifiers”” (e.g. containing (e.g. containing
locations or people that might change)locations or people that might change) Substitute new, simple keys for long,Substitute new, simple keys for long,
composite keyscomposite keys
![Page 19: Modern Database Management 7th Edition, Chapter 3](https://reader034.vdocuments.site/reader034/viewer/2022050800/586cc9521a28ab427c8b7f4d/html5/thumbnails/19.jpg)
1919Chapter 3 ©© 2005 by Prentice Hall 2005 by Prentice Hall
Figure 3-9a – Simple key attribute
The key is underlined
![Page 20: Modern Database Management 7th Edition, Chapter 3](https://reader034.vdocuments.site/reader034/viewer/2022050800/586cc9521a28ab427c8b7f4d/html5/thumbnails/20.jpg)
2020Chapter 3 ©© 2005 by Prentice Hall 2005 by Prentice Hall
Figure 3-9b – Composite key attribute
The key is composed of two subparts
![Page 21: Modern Database Management 7th Edition, Chapter 3](https://reader034.vdocuments.site/reader034/viewer/2022050800/586cc9521a28ab427c8b7f4d/html5/thumbnails/21.jpg)
2121Chapter 3 ©© 2005 by Prentice Hall 2005 by Prentice Hall
Figure 3-8 – Entity with a multivalued attribute (Skill) andderived attribute (Years_Employed)
Derived from date employed and current date
What’s wrong with this?
Multivalued: an employee can have more than one skill
![Page 22: Modern Database Management 7th Edition, Chapter 3](https://reader034.vdocuments.site/reader034/viewer/2022050800/586cc9521a28ab427c8b7f4d/html5/thumbnails/22.jpg)
2222Chapter 3 ©© 2005 by Prentice Hall 2005 by Prentice Hall
Figure 3-19 – An attribute that is both multivalued and composite
This is anexample oftime-stamping
![Page 23: Modern Database Management 7th Edition, Chapter 3](https://reader034.vdocuments.site/reader034/viewer/2022050800/586cc9521a28ab427c8b7f4d/html5/thumbnails/23.jpg)
2323Chapter 3 ©© 2005 by Prentice Hall 2005 by Prentice Hall
Problem: Dependent_name not unique(not even together with Date_of_Birth)
![Page 24: Modern Database Management 7th Edition, Chapter 3](https://reader034.vdocuments.site/reader034/viewer/2022050800/586cc9521a28ab427c8b7f4d/html5/thumbnails/24.jpg)
2424Chapter 3 ©© 2005 by Prentice Hall 2005 by Prentice Hall
Strong vs. Weak Entity Types, andStrong vs. Weak Entity Types, andIdentifying RelationshipsIdentifying Relationships
Strong entity typeStrong entity type exist independently of other types of entitiesexist independently of other types of entities has its own unique identifierhas its own unique identifier represented with single-line rectanglerepresented with single-line rectangle
Weak entity typeWeak entity type dependent on a strong entitydependent on a strong entity…… cannot exist on its own cannot exist on its own does does notnot have a unique identifier have a unique identifier represented with double-line rectanglerepresented with double-line rectangle
Identifying relationshipIdentifying relationship links strong entity type to weak entity typelinks strong entity type to weak entity type represented with double line diamondrepresented with double line diamond
![Page 25: Modern Database Management 7th Edition, Chapter 3](https://reader034.vdocuments.site/reader034/viewer/2022050800/586cc9521a28ab427c8b7f4d/html5/thumbnails/25.jpg)
2525Chapter 3 ©© 2005 by Prentice Hall 2005 by Prentice Hall
Discussion of weak entitiesDiscussion of weak entities
Always possible to add Always possible to add ””artificialartificial”” identifier identifierto avoid them.to avoid them.
However, sometimes more natural to formHowever, sometimes more natural to forma composite key involving a foreign keya composite key involving a foreign keygiven by the identifying relationship.given by the identifying relationship.
Saves a bit of space too...Saves a bit of space too...
![Page 26: Modern Database Management 7th Edition, Chapter 3](https://reader034.vdocuments.site/reader034/viewer/2022050800/586cc9521a28ab427c8b7f4d/html5/thumbnails/26.jpg)
2626Chapter 3 ©© 2005 by Prentice Hall 2005 by Prentice Hall
Associative EntitiesAssociative Entities ItIt’’s an s an entity type entity type –– it has attributes, identifier. it has attributes, identifier.
AND itAND it’’s a s a relationshiprelationship –– it links entities together. it links entities together. Should be seen as a way of visualizing the above,Should be seen as a way of visualizing the above,
butbut: Behaves in all ways just like an entity type.: Behaves in all ways just like an entity type.