chapter 3: modeling data in the organization · 2005-02-24 · © 2005 by prentice hall 1 chapter...

40
© 2005 by Prentice Hall 2005 by Prentice Hall 1 Chapter 3: Chapter 3: Modeling Data in the Modeling Data in the Organization Organization Modern Database Management Modern Database Management 7 7 th th Edition Edition Jeffrey A. Hoffer, Mary B. Prescott, Jeffrey A. Hoffer, Mary B. Prescott, Fred R. McFadden Fred R. McFadden

Upload: others

Post on 07-May-2020

4 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Chapter 3: Modeling Data in the Organization · 2005-02-24 · © 2005 by Prentice Hall 1 Chapter 3: Modeling Data in the Organization Modern Database Management 7th Edition Jeffrey

©© 2005 by Prentice Hall 2005 by Prentice Hall 11

Chapter 3:Chapter 3:Modeling Data in theModeling Data in the

OrganizationOrganization

Modern Database ManagementModern Database Management77thth Edition Edition

Jeffrey A. Hoffer, Mary B. Prescott,Jeffrey A. Hoffer, Mary B. Prescott,Fred R. McFaddenFred R. McFadden

Page 2: Chapter 3: Modeling Data in the Organization · 2005-02-24 · © 2005 by Prentice Hall 1 Chapter 3: Modeling Data in the Organization Modern Database Management 7th Edition Jeffrey

22Chapter 3 ©© 2005 by Prentice Hall 2005 by Prentice Hall

SDLC Revisited SDLC Revisited –– Data Modeling is an Data Modeling is anAnalysis ActivityAnalysis Activity(figures 2-4, 2-5)(figures 2-4, 2-5)

Purpose – thorough analysisDeliverable – functional system specifications

Database activity – conceptual data modeling

Project Identification and Selection

Project Initiation and Planning

Analysis

Physical Design

Implementation

Maintenance

Logical Design

Analysis

Project Initiation and Planning

Page 3: Chapter 3: Modeling Data in the Organization · 2005-02-24 · © 2005 by Prentice Hall 1 Chapter 3: Modeling Data in the Organization Modern Database Management 7th Edition Jeffrey

33Chapter 3 ©© 2005 by Prentice Hall 2005 by Prentice Hall

Simpelt E-R diagramSimpelt E-R diagramLavet i Omnigraffle, som man selv gratis kan installere på Mac.

ITU Maclab er i 2A54.

Page 4: Chapter 3: Modeling Data in the Organization · 2005-02-24 · © 2005 by Prentice Hall 1 Chapter 3: Modeling Data in the Organization Modern Database Management 7th Edition Jeffrey

44Chapter 3 ©© 2005 by Prentice Hall 2005 by Prentice Hall

Sample E-R Diagram (Figure 3-1)

Page 5: Chapter 3: Modeling Data in the Organization · 2005-02-24 · © 2005 by Prentice Hall 1 Chapter 3: Modeling Data in the Organization Modern Database Management 7th Edition Jeffrey

55Chapter 3 ©© 2005 by Prentice Hall 2005 by Prentice Hall

Relationshipdegrees specifynumber ofentity typesinvolved

Entitysymbols

A special entitythat is also arelationship

Relationship symbols

Relationshipcardinalitiesspecify howmany of eachentity type isallowed

Attributesymbols

Page 6: Chapter 3: Modeling Data in the Organization · 2005-02-24 · © 2005 by Prentice Hall 1 Chapter 3: Modeling Data in the Organization Modern Database Management 7th Edition Jeffrey

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

What Should an Entity Be?What Should an Entity Be? SHOULD BE:SHOULD BE:

An object that will have many instances inAn object that will have many instances inthe databasethe database

An object that will be composed of multipleAn object that will be composed of multipleattributesattributes

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 7: Chapter 3: Modeling Data in the Organization · 2005-02-24 · © 2005 by Prentice Hall 1 Chapter 3: Modeling Data in the Organization Modern Database Management 7th Edition Jeffrey

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

Inappropriate entities

System userSystem user System outputSystem output

Appropriate entities

Figure 3-4

Page 8: Chapter 3: Modeling Data in the Organization · 2005-02-24 · © 2005 by Prentice Hall 1 Chapter 3: Modeling Data in the Organization Modern Database Management 7th Edition Jeffrey

88Chapter 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, order og kredit:information om kunderne, order og kredit: Navne og adresserNavne og adresser TelefonnumreTelefonnumre Kundetyper (privat eller forretning)Kundetyper (privat eller forretning) 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 9: Chapter 3: Modeling Data in the Organization · 2005-02-24 · © 2005 by Prentice Hall 1 Chapter 3: Modeling Data in the Organization Modern Database Management 7th Edition Jeffrey

99Chapter 3 ©© 2005 by Prentice Hall 2005 by Prentice Hall

More on RelationshipsMore on Relationships Relationship Types vs. Relationship InstancesRelationship Types vs. Relationship Instances

The relationship type is modeled as the diamondThe relationship type is modeled as the diamondand lines between entity typesand lines between entity types……the instance isthe instance isbetween specific entity instancesbetween specific entity instances

Relationships can have attributesRelationships can have attributes These describe features pertaining to the associationThese describe features pertaining to the association

between the entities in the relationshipbetween the entities in the relationship

Two entities can have more than one type ofTwo entities can have more than one type ofrelationship between them (multiplerelationship between them (multiplerelationships)relationships)

Associative Entity Associative Entity –– combination of combination ofrelationship and entityrelationship and entity

Page 10: Chapter 3: Modeling Data in the Organization · 2005-02-24 · © 2005 by Prentice Hall 1 Chapter 3: Modeling Data in the Organization Modern Database Management 7th Edition Jeffrey

1010Chapter 3 ©© 2005 by Prentice Hall 2005 by Prentice Hall

Page 11: Chapter 3: Modeling Data in the Organization · 2005-02-24 · © 2005 by Prentice Hall 1 Chapter 3: Modeling Data in the Organization Modern Database Management 7th Edition Jeffrey

1111Chapter 3 ©© 2005 by Prentice Hall 2005 by Prentice Hall

Degree of RelationshipsDegree of Relationships

Degree of a relationship is theDegree of a relationship is thenumber of entity types thatnumber of entity types thatparticipate in itparticipate in itUnary RelationshipUnary RelationshipBinary RelationshipBinary RelationshipTernary RelationshipTernary Relationship

Page 12: Chapter 3: Modeling Data in the Organization · 2005-02-24 · © 2005 by Prentice Hall 1 Chapter 3: Modeling Data in the Organization Modern Database Management 7th Edition Jeffrey

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

Degree of relationships – from Figure 3-2

One entityrelated toanother ofthe sameentity type

Entities oftwo differenttypes relatedto each other Entities of three

different typesrelated to eachother

Page 13: Chapter 3: Modeling Data in the Organization · 2005-02-24 · © 2005 by Prentice Hall 1 Chapter 3: Modeling Data in the Organization Modern Database Management 7th Edition Jeffrey

1313Chapter 3 ©© 2005 by Prentice Hall 2005 by Prentice Hall

Cardinality of RelationshipsCardinality of Relationships

One-to-OneOne-to-One Each entity in the relationship will have exactly oneEach entity in the relationship will have exactly one

related entityrelated entity

One-to-ManyOne-to-Many An entity on one side of the relationship can haveAn entity on one side of the relationship can have

many related entities, but an entity on the other sidemany related entities, but an entity on the other sidewill have a maximum of one related entitywill have a maximum of one related entity

Many-to-ManyMany-to-Many Entities on both sides of the relationship can haveEntities on both sides of the relationship can have

many related entities on the other sidemany related entities on the other side

Page 14: Chapter 3: Modeling Data in the Organization · 2005-02-24 · © 2005 by Prentice Hall 1 Chapter 3: Modeling Data in the Organization Modern Database Management 7th Edition Jeffrey

1414Chapter 3 ©© 2005 by Prentice Hall 2005 by Prentice Hall

Cardinality ConstraintsCardinality Constraints

Cardinality Constraints - the number ofCardinality Constraints - the number ofinstances of one entity that can or must beinstances of one entity that can or must beassociated with each instance of anotherassociated with each instance of anotherentityentity

Minimum CardinalityMinimum Cardinality If zero, then optionalIf zero, then optional If one or more, then mandatoryIf one or more, then mandatory

Maximum CardinalityMaximum Cardinality The maximum numberThe maximum number

Page 15: Chapter 3: Modeling Data in the Organization · 2005-02-24 · © 2005 by Prentice Hall 1 Chapter 3: Modeling Data in the Organization Modern Database Management 7th Edition Jeffrey

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

Page 16: Chapter 3: Modeling Data in the Organization · 2005-02-24 · © 2005 by Prentice Hall 1 Chapter 3: Modeling Data in the Organization Modern Database Management 7th Edition Jeffrey

1616Chapter 3 ©© 2005 by Prentice Hall 2005 by Prentice Hall

Page 17: Chapter 3: Modeling Data in the Organization · 2005-02-24 · © 2005 by Prentice Hall 1 Chapter 3: Modeling Data in the Organization Modern Database Management 7th Edition Jeffrey

1717Chapter 3 ©© 2005 by Prentice Hall 2005 by Prentice Hall

Basic relationship with only maximum cardinalities showing –Figure 3-16a

Mandatory minimum cardinalities – Figure 3-17a

Page 18: Chapter 3: Modeling Data in the Organization · 2005-02-24 · © 2005 by Prentice Hall 1 Chapter 3: Modeling Data in the Organization Modern Database Management 7th Edition Jeffrey

1818Chapter 3 ©© 2005 by Prentice Hall 2005 by Prentice Hall

Figure 3-17cOptional cardinalities with unary degree, one-to-one relationship

Page 19: Chapter 3: Modeling Data in the Organization · 2005-02-24 · © 2005 by Prentice Hall 1 Chapter 3: Modeling Data in the Organization Modern Database Management 7th Edition Jeffrey

1919Chapter 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

Page 20: Chapter 3: Modeling Data in the Organization · 2005-02-24 · © 2005 by Prentice Hall 1 Chapter 3: Modeling Data in the Organization Modern Database Management 7th Edition Jeffrey

2020Chapter 3 ©© 2005 by Prentice Hall 2005 by Prentice Hall

Figure 3-12c -- A ternary relationship with attributes

Page 21: Chapter 3: Modeling Data in the Organization · 2005-02-24 · © 2005 by Prentice Hall 1 Chapter 3: Modeling Data in the Organization Modern Database Management 7th Edition Jeffrey

2121Chapter 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 22: Chapter 3: Modeling Data in the Organization · 2005-02-24 · © 2005 by Prentice Hall 1 Chapter 3: Modeling Data in the Organization Modern Database Management 7th Edition Jeffrey

2222Chapter 3 ©© 2005 by Prentice Hall 2005 by Prentice Hall

Page 23: Chapter 3: Modeling Data in the Organization · 2005-02-24 · © 2005 by Prentice Hall 1 Chapter 3: Modeling Data in the Organization Modern Database Management 7th Edition Jeffrey

2323Chapter 3 ©© 2005 by Prentice Hall 2005 by Prentice Hall

Entities can be related to one another in more than one way

Page 24: Chapter 3: Modeling Data in the Organization · 2005-02-24 · © 2005 by Prentice Hall 1 Chapter 3: Modeling Data in the Organization Modern Database Management 7th Edition Jeffrey

2424Chapter 3 ©© 2005 by Prentice Hall 2005 by Prentice Hall

Here,maxcardinalityconstraint is 4

Page 25: Chapter 3: Modeling Data in the Organization · 2005-02-24 · © 2005 by Prentice Hall 1 Chapter 3: Modeling Data in the Organization Modern Database Management 7th Edition Jeffrey

2525Chapter 3 ©© 2005 by Prentice Hall 2005 by Prentice Hall

E-R diagram E-R diagram til problemsessiontil problemsession

Page 26: Chapter 3: Modeling Data in the Organization · 2005-02-24 · © 2005 by Prentice Hall 1 Chapter 3: Modeling Data in the Organization Modern Database Management 7th Edition Jeffrey

2626Chapter 3 ©© 2005 by Prentice Hall 2005 by Prentice Hall

AttributesAttributes

Attribute - property or characteristic of anAttribute - property or characteristic of anentity typeentity type

Classifications of attributes:Classifications of attributes: Required versus Optional AttributesRequired versus Optional Attributes Simple versus Composite AttributeSimple versus Composite Attribute Single-Valued versus Single-Valued versus Multivalued Multivalued AttributeAttribute Stored versus Derived AttributesStored versus Derived Attributes Identifier AttributesIdentifier Attributes

Page 27: Chapter 3: Modeling Data in the Organization · 2005-02-24 · © 2005 by Prentice Hall 1 Chapter 3: Modeling Data in the Organization Modern Database Management 7th Edition Jeffrey

2727Chapter 3 ©© 2005 by Prentice Hall 2005 by Prentice Hall

Identifiers (Keys)Identifiers (Keys)

Identifier (Key) - An attribute (orIdentifier (Key) - An attribute (orcombination of attributes) that uniquelycombination of attributes) that uniquelyidentifies individual instances of an entityidentifies individual instances of an entitytypetype

Simple Key versus Composite KeySimple Key versus Composite Key Candidate Key Candidate Key –– an attribute that could be an attribute that could be

a keya key……satisfies the requirements for beingsatisfies the requirements for beinga keya key

Page 28: Chapter 3: Modeling Data in the Organization · 2005-02-24 · © 2005 by Prentice Hall 1 Chapter 3: Modeling Data in the Organization Modern Database Management 7th Edition Jeffrey

2828Chapter 3 ©© 2005 by Prentice Hall 2005 by Prentice Hall

Characteristics of IdentifiersCharacteristics of Identifiers

Will not change in valueWill not change in value Will not be nullWill not be null No intelligent identifiers (e.g. containingNo intelligent identifiers (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 29: Chapter 3: Modeling Data in the Organization · 2005-02-24 · © 2005 by Prentice Hall 1 Chapter 3: Modeling Data in the Organization Modern Database Management 7th Edition Jeffrey

2929Chapter 3 ©© 2005 by Prentice Hall 2005 by Prentice Hall

Figure 3-7 – A composite attribute

An attributebroken intocomponent parts

Page 30: Chapter 3: Modeling Data in the Organization · 2005-02-24 · © 2005 by Prentice Hall 1 Chapter 3: Modeling Data in the Organization Modern Database Management 7th Edition Jeffrey

3030Chapter 3 ©© 2005 by Prentice Hall 2005 by Prentice Hall

Figure 3-9a – Simple key attribute

The key is underlined

Page 31: Chapter 3: Modeling Data in the Organization · 2005-02-24 · © 2005 by Prentice Hall 1 Chapter 3: Modeling Data in the Organization Modern Database Management 7th Edition Jeffrey

3131Chapter 3 ©© 2005 by Prentice Hall 2005 by Prentice Hall

Figure 3-9b – Composite key attribute

The key is composed of two subparts

Page 32: Chapter 3: Modeling Data in the Organization · 2005-02-24 · © 2005 by Prentice Hall 1 Chapter 3: Modeling Data in the Organization Modern Database Management 7th Edition Jeffrey

3232Chapter 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 33: Chapter 3: Modeling Data in the Organization · 2005-02-24 · © 2005 by Prentice Hall 1 Chapter 3: Modeling Data in the Organization Modern Database Management 7th Edition Jeffrey

3333Chapter 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 34: Chapter 3: Modeling Data in the Organization · 2005-02-24 · © 2005 by Prentice Hall 1 Chapter 3: Modeling Data in the Organization Modern Database Management 7th Edition Jeffrey

3434Chapter 3 ©© 2005 by Prentice Hall 2005 by Prentice Hall

Multivalued attributes can be represented as relationships

Page 35: Chapter 3: Modeling Data in the Organization · 2005-02-24 · © 2005 by Prentice Hall 1 Chapter 3: Modeling Data in the Organization Modern Database Management 7th Edition Jeffrey

3535Chapter 3 ©© 2005 by Prentice Hall 2005 by Prentice Hall

Strong vs. Weak Entities, andStrong vs. Weak Entities, andIdentifying RelationshipsIdentifying Relationships

Strong entitiesStrong entities 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 entityWeak entity dependent on a strong entitydependent on a strong entity……cannot exist on its owncannot exist on its own does not have a unique identifierdoes not have a unique identifier represented with double-line rectanglerepresented with double-line rectangle

Identifying relationshipIdentifying relationship links strong entities to weak entitieslinks strong entities to weak entities represented with double line diamondrepresented with double line diamond

Page 36: Chapter 3: Modeling Data in the Organization · 2005-02-24 · © 2005 by Prentice Hall 1 Chapter 3: Modeling Data in the Organization Modern Database Management 7th Edition Jeffrey

3636Chapter 3 ©© 2005 by Prentice Hall 2005 by Prentice Hall

Strong entity Weak entityIdentifying relationship

Page 37: Chapter 3: Modeling Data in the Organization · 2005-02-24 · © 2005 by Prentice Hall 1 Chapter 3: Modeling Data in the Organization Modern Database Management 7th Edition Jeffrey

3737Chapter 3 ©© 2005 by Prentice Hall 2005 by Prentice Hall

Associative EntitiesAssociative Entities ItIt’’s an s an entity entity –– it has attributes it has attributes

AND itAND it’’s a s a relationship relationship –– it links entities together it links entities together

When should a When should a relationship with attributesrelationship with attributes instead be an instead be anassociative entityassociative entity?? All relationships for the associative entity should be manyAll relationships for the associative entity should be many The associative entity could have meaning independent of theThe associative entity could have meaning independent of the

other entitiesother entities The associative entity preferably has a unique identifier, and shouldThe associative entity preferably has a unique identifier, and should

also have other attributesalso have other attributes The associative entity may participate in other relationships otherThe associative entity may participate in other relationships other

than the entities of the associated relationshipthan the entities of the associated relationship Ternary relationships should be converted to associative entitiesTernary relationships should be converted to associative entities

Page 38: Chapter 3: Modeling Data in the Organization · 2005-02-24 · © 2005 by Prentice Hall 1 Chapter 3: Modeling Data in the Organization Modern Database Management 7th Edition Jeffrey

3838Chapter 3 ©© 2005 by Prentice Hall 2005 by Prentice Hall

Figure 3-11b – An associative entity (CERTIFICATE)

Associative entity involves a rectangle with a diamond inside.Note that the many-to-many cardinality symbols face towardthe associative entity and not toward the other entities

Page 39: Chapter 3: Modeling Data in the Organization · 2005-02-24 · © 2005 by Prentice Hall 1 Chapter 3: Modeling Data in the Organization Modern Database Management 7th Edition Jeffrey

3939Chapter 3 ©© 2005 by Prentice Hall 2005 by Prentice Hall

Figure 3-13c – An associative entity – bill of materials structure

This could just be a relationship withattributes…it’s a judgment call

Page 40: Chapter 3: Modeling Data in the Organization · 2005-02-24 · © 2005 by Prentice Hall 1 Chapter 3: Modeling Data in the Organization Modern Database Management 7th Edition Jeffrey

4040Chapter 3 ©© 2005 by Prentice Hall 2005 by Prentice Hall

Figure 3-18 – Ternary relationship as an associative entity