chapter 5 understanding entity relationship diagrams
TRANSCRIPT
Chapter 5Chapter 5Understanding Entity Relationship Diagrams
McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved.
Outline Outline
Notation basicsUnderstanding relationshipsGeneralization hierarchiesDiagram rules
McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved.
Basic SymbolsBasic Symbols
Entity Typesymbol Relationship
symbol
Primary Key
AttributesRelationship
name
Entity Typename
CourseNoCrsDescCrsUnits
Course
OfferNoOffLocationOffTime
Offering
Has
McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved.
CardinalitiesCardinalities
Course Offering
Course1 Offering1
Course2
Course3
Offering2
Offering3
Offering4
McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved.
Cardinality NotationCardinality Notation
Inside symbol:minimum cardinality
CourseNoCrsDescCrsUnits
Course
OfferNoOffLocationOffTime
Offering
Has
Perpendicular line:one cardinality
Outside symbol:maximum cardinality
Circle: zerocardinality
Crow's foot: manycardinality
McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved.
Classification of CardinalitiesClassification of Cardinalities
Minimum cardinality based– Mandatory: existence dependent– Optional
Maximum cardinality based– Functional– 1-M– M-N– 1-1
McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved.
Summary of CardinalitiesSummary of CardinalitiesClassification Cardinality Restrictions
Mandatory Minimum cardinality 1
Optional Minimum cardinality = 0
Functional or single-valued
Maximum cardinality = 1
1-M Maximum cardinality = 1 in one direction and Maximum cardinality > 1 in the other direction.
M-N Maximum cardinality is > 1 in both directions.
1-1 Maximum cardinality = 1 in both directions.
McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved.
More Relationship ExamplesMore Relationship Examples
FacSSNFacSalaryFacRankFacHireDate
Faculty
OfferNoOffLocationOffTime
Offering
TeamTeachesOfficeNoOffPhoneOffType
Office
WorksIn
McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved.
Comparison to Access NotationComparison to Access Notation
CourseNoCrsDescCrsUnits
Course
OfferNoOffLocationOffTime
Offering
Has
ERD (Crow's Foot)
CourseCoursenoCrsDescCrsUnits
1 8OfferingOfferNo
CourseNoOffLocation
OffTime...
Access Relationship Diagram
McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved.
Understanding RelationshipsUnderstanding Relationships
Identification dependencyM-N relationships with attributesSelf identifying relationshipsM-way relationshipsEquivalence between M-N and 1-M
relationships
McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved.
Identification DependencyIdentification Dependency
BldgIDBldgNameBldgLocation
Building
RoomNoRoomCapacity
Room
Contains
Identification Dependency Symbols: Solid relationship line for identifying
relationships Diagonal lines in the corners denote
weak entities.
McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved.
M-N Relationships M-N Relationships with Attributeswith Attributes
StdSSNStdName
StudentOfferNoOffLocationOffTime
Offering
EnrollsIn
EnrGrade
attribute of relationship
McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved.
M-N Relationships M-N Relationships with Attributes (II)with Attributes (II)
AuthNoAuthName
AuthorISBNTitle
Book
AuthOrder
b) Writes relationship
Writes
PartNoPartName
PartSuppNoSuppName
Supplier
Qty
Provides
a) Provides relationship
McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved.
Instance Diagrams for Self-Instance Diagrams for Self-Referencing RelationshipsReferencing Relationships
Faculty1
Faculty2 Faculty3
Faculty4 Faculty5
IS300
IS320
IS480 IS460
IS461
(a) Supervises (b) PreReqTo
McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved.
ERD Notation for Self-ERD Notation for Self-Referencing RelationshipsReferencing Relationships
FacSSNFacName
Faculty
a) manager-subordinate
Supervises
b) course prerequisites
CourseNoCrsDesc
Course PrereqTo
McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved.
Associative Entity Types for Associative Entity Types for M-way RelationshipsM-way Relationships
PartNoPartName
PartSuppNoSuppName
Supplier
Associativeentity type
ProjNoProjName
Project
UsesPart-Uses
Supp-Uses
Proj-Uses
McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved.
Relationship EquivalenceRelationship Equivalence
Replace M-N relationship – Associative entity type– Two identifying 1-M relationships
M-N relationship versus associative entity type– Largely preference– Associative entity type is more flexible in some
situations
McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved.
Associative Entity Type ExampleAssociative Entity Type Example
StdSSNStdName
StudentOfferNoOffLocationOffTime
Offering
EnrGrade
EnrollmentRegisters GrantsAttDatePresent
Attendance
RecordedFor
McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved.
Generalization HierarchiesGeneralization Hierarchies
EmployeeEmpNo
EmpNameEmpHireDate
...
SalaryEmpEmpSalary
HourlyEmpEmpRate
generalization hierarchysymbol
supertype
subtypes
McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved.
InheritanceInheritance
Subtypes inherit attributes of supertypes (direct and indirect)
Allows abbreviation of attribute listApplies to code (methods) as well as
attributes (data)
McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved.
Generalization ConstraintsGeneralization Constraints
BondRate
FaceValue
StockOutShares
IssuedShares
SecuritySymbol
SecNameLastClose
D,C
DisjointnessConstraint
CompletenessConstraint
McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved.
Multiple Levels of Multiple Levels of GeneralizationGeneralization
SecuritySymbol
SecNameLastClose
StockOutShares
IssuedShares
BondRate
FaceValue
D,C
CommonPERatioDividend
PreferredCallPriceArrears
D,C
McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved.
Comprehensive ExampleComprehensive Example
OfferingOfferNoOffLocationOffTime
EnrGrade
EnrollmentRegisters
Grants
CourseNoCrsDescCrsUnits
Course
FacultyFacSalaryFacRankFacHireHate
SSNNameCityStateZip
UnivPerson
Has
Teaches
Supervises
CStudentStdClassStdMajorStdGPA
McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved.
Diagram RulesDiagram Rules
Ensure that ERD notation is correctly usedSimilar to syntax rules for a computer
languageCompleteness rules: no missing
specificationsConsistency rules: no conflicts among
specificationsSupported by the ER Assistant
McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved.
Completeness RulesCompleteness Rules Primary Key Rule: all entity types have a PK (direct,
indirect, or inherited) Naming Rule: all entity types, relationships, and
attributes have a name Cardinality Rule: cardinality is specified in both
directions for each relationship Entity Participation Rule: all entity types participate in an
at least one relationship except for entity types in a generalization hierarchy
Generalization Hierarchy Participation Rule: at least one entity type in a generalization hierarchy participates in a relationship
McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved.
Primary Key Rule IssuePrimary Key Rule Issue
Primary key rule is simple in most casesFor some weak entities, the PK rule is
subtle
– Weak entity with only one 1-M identifying relationship
– Weak entity must have a local key to augment the borrowed PK from the parent entity type
– Violation of PK rule if local key is missing
McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved.
PK Rule Violation ExamplePK Rule Violation Example
BldgIDBldgNameBldgLocation
BuildingRoomRoomNoRoomCapacity
Contains
PK rule violation A single 1-M identifying relationship Room does not have a local key.
McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved.
Naming Consistency RulesNaming Consistency Rules
Entity Name Rule: entity type names must be unique
Attribute Name Rule: attribute names must be unique within each entity type and relationship
Inherited Attribute Rule: attribute names in a subtype do not match inherited (direct or indirect) attribute names.
McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved.
Connection Consistency RulesConnection Consistency Rules
Relationship/Entity Connection Rule: relationships connect two entity types (not necessarily distinct)
Relationship/Relationship Connection Rule: relationships are not connected to other relationships
Redundant Foreign Key Rule: foreign keys are not used.
McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved.
Identification Dependency RulesIdentification Dependency Rules
Weak entity rule: weak entities have at least one identifying relationship
Identifying relationship rule: at least one participating entity type must be weak for each identifying relationship
Identification dependency cardinality rule: the minimum and maximum cardinality must equal 1 for a weak entity in all identifying relationships
McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved.
Example of Diagram ErrorsExample of Diagram Errors
OfferingOfferNoOffLocationOffTimeCourseNo
EnrGrade
EnrollmentRegisters Grants
CourseNoCrsDescCrsUnits
Course
FacultyFacSalaryFacRankFacHireHate
SSNNameCityStateZip
UnivPerson
Has
Teaches
Supervises
CStudentStdClassStdMajorStdGPA
Rule 6 Violation(Weak Entity)
Rule 7 Violation(Identifying Relationship)Rule 8 Violation
(Id Dependency Cardinality)
Rule 9 Violation(Redundant FK)
McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved.
Corrected ERDCorrected ERD
OfferingOfferNoOffLocationOffTime
EnrGrade
EnrollmentRegisters
Grants
CourseNoCrsDescCrsUnits
Course
FacultyFacSalaryFacRankFacHireHate
SSNNameCityStateZip
UnivPerson
Has
Teaches
Supervises
CStudentStdClassStdMajorStdGPA
McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved.
Support in the ER AssistantSupport in the ER Assistant
Version 2 of the ER Assistant supports the diagram rules
Relationship formation rules are supported by diagram construction
Other rules are supported by the Check Diagram feature
For the Redundant Foreign Key rule, the ER Assistant detects FKs that have the same name as the associated PKs
McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved.
SummarySummary
Data modeling is an important skillCrow’s Foot ERD notation is widely usedUse notation preciselyUse the diagram rules to ensure structural
consistency and completenessUnderstanding the ERD notation is a
prerequisite to applying the notation on business problems