26
© 2005 by Prentice Hall 2005 by Prentice Hall 1 Modern Database Management Modern Database Management 7 7 th th Edition, Chapter 3 Edition, Chapter 3 Jeffrey A. Hoffer, Mary B. Prescott, Jeffrey A. Hoffer, Mary B. Prescott, Fred R. McFadden Fred R. McFadden Slides edited by Rasmus Pagh Slides edited by Rasmus Pagh

Modern Database Management 7th Edition, Chapter 3

Embed Size (px)

Citation preview

Page 1: Modern Database Management 7th Edition, Chapter 3

©© 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

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

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

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

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

66Chapter 3 ©© 2005 by Prentice Hall 2005 by Prentice Hall

Page 7: Modern Database Management 7th Edition, Chapter 3

77Chapter 3 ©© 2005 by Prentice Hall 2005 by Prentice Hall

Page 8: Modern Database Management 7th Edition, Chapter 3

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

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

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

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

1212Chapter 3 ©© 2005 by Prentice Hall 2005 by Prentice Hall

Page 13: Modern Database Management 7th Edition, Chapter 3

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

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

1515Chapter 3 ©© 2005 by Prentice Hall 2005 by Prentice Hall

Page 16: Modern Database Management 7th Edition, Chapter 3

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

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

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

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

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

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

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

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

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

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

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.