Professional Documents
Culture Documents
14 Relationships
14 Relationships
14 Relationships
Lecture 14:
Entity Relationship Modelling
2004-5 Steve Easterbrook. This presentation is available free for non-commercial use with attribution under a creative commons license.
University of Toronto
Entity-Relationship Schema
Describes data requirements for a new information system
Direct, easy-to-understand graphical notation
Translates readily to relational schema for database design
But more abstract than relational schema
E.g. can represent an entity without knowing its properties
Entities:
classes of objects with properties in common and an autonomous existence
E.g. City, Department, Employee, Purchase and Sale
Relationships:
logical links between two or more entities.
E.g. Residence is a relationship that can exist between the City and Employee
2004-5 Steve Easterbrook. This presentation is available free for non-commercial use with attribution under a creative commons license.
University of Toronto
Examples
Adapted from chapter 5 of Atzeni et al, Database Systems McGraw Hill, 1999
2004-5 Steve Easterbrook. This presentation is available free for non-commercial use with attribution under a creative commons license.
University of Toronto
Exam
2004-5 Steve Easterbrook. This presentation is available free for non-commercial use with attribution under a creative commons license.
University of Toronto
Course
Meets
Room
Meets is a relationship.
Its instances describe particular meetings.
Each meeting has exactly one associated course and room
Course instances
Meets instances
Room instances
2004-5 Steve Easterbrook. This presentation is available free for non-commercial use with attribution under a creative commons license.
University of Toronto
Recursive Relationships
Adapted from chapter 5 of Atzeni et al, Database Systems McGraw Hill, 1999
2004-5 Steve Easterbrook. This presentation is available free for non-commercial use with attribution under a creative commons license.
University of Toronto
Ternary Relationships
Adapted from chapter 5 of Atzeni et al, Database Systems McGraw Hill, 1999
2004-5 Steve Easterbrook. This presentation is available free for non-commercial use with attribution under a creative commons license.
University of Toronto
AND/XOR Relationships
Each Order
either contains a
part or requests
a service, but not
both
2004-5 Steve Easterbrook. This presentation is available free for non-commercial use with attribution under a creative commons license.
University of Toronto
Attributes
Adapted from chapter 5 of Atzeni et al, Database Systems McGraw Hill, 1999
2004-5 Steve Easterbrook. This presentation is available free for non-commercial use with attribution under a creative commons license.
University of Toronto
Composite Attributes
Adapted from chapter 5 of Atzeni et al, Database Systems McGraw Hill, 1999
2004-5 Steve Easterbrook. This presentation is available free for non-commercial use with attribution under a creative commons license.
10
University of Toronto
2004-5 Steve Easterbrook. This presentation is available free for non-commercial use with attribution under a creative commons license.
11
University of Toronto
Cardinalities
Adapted from chapter 5 of Atzeni et al, Database Systems McGraw Hill, 1999
2004-5 Steve Easterbrook. This presentation is available free for non-commercial use with attribution under a creative commons license.
12
University of Toronto
Cardinality Example
Adapted from chapter 5 of Atzeni et al, Database Systems McGraw Hill, 1999
A course
meets twice
a week
Course
(2,2)
A day can
have an
unlimited
number of
meetings
Meets
(0,N)
(0,40)
Room
A room can
have up to
40 meetings
per week
Day
2004-5 Steve Easterbrook. This presentation is available free for non-commercial use with attribution under a creative commons license.
13
University of Toronto
Instantiating ER diagrams
Adapted from chapter 5 of Atzeni et al, Database Systems McGraw Hill, 1999
(2,2)
Meets
(0,40)
Room
2004-5 Steve Easterbrook. This presentation is available free for non-commercial use with attribution under a creative commons license.
14
University of Toronto
Instantiating ER diagrams
Adapted from chapter 5 of Atzeni et al, Database Systems McGraw Hill, 1999
(2,2)
Meets
(0,40)
Room
Illegal Instantiations
2004-5 Steve Easterbrook. This presentation is available free for non-commercial use with attribution under a creative commons license.
15
University of Toronto
Cardinalities of Attributes
Adapted from chapter 5 of Atzeni et al, Database Systems McGraw Hill, 1999
Multi-valued attribute
cardinalities are problematic
Usually better modelled with additional
entities linked by one-to-many (or manyto-many) relationships
2004-5 Steve Easterbrook. This presentation is available free for non-commercial use with attribution under a creative commons license.
16
University of Toronto
Identifiers
Adapted from chapter 5 of Atzeni et al, Database Systems McGraw Hill, 1999
internal, single-attribute
external, multi-attribute
internal, multi-attribute
2004-5 Steve Easterbrook. This presentation is available free for non-commercial use with attribution under a creative commons license.
17
University of Toronto
Notes on Identifiers
Adapted from chapter 5 of Atzeni et al, Database Systems McGraw Hill, 1999
Cycles
An external identifier can involve an entity that is in its turn identified
externally, as long as cycles are not generated;
Multiple identifiers
Each entity must have at least one (internal or external) identifier
An entity can have more than one identifier
Note: if there is more than one identifier, then the attributes and entities
involved in an identification can be optional (minimum cardinality equal to 0).
2004-5 Steve Easterbrook. This presentation is available free for non-commercial use with attribution under a creative commons license.
18
University of Toronto
2004-5 Steve Easterbrook. This presentation is available free for non-commercial use with attribution under a creative commons license.
19
University of Toronto
2004-5 Steve Easterbrook. This presentation is available free for non-commercial use with attribution under a creative commons license.
20
University of Toronto
Generalizations
Adapted from chapter 5 of Atzeni et al, Database Systems McGraw Hill, 1999
Inheritance:
Every instance of a child entity is also an instance of the parent entity
Every property of the parent entity (attribute, identifier, relationship or
other generalization) is also a property of a child entity
2004-5 Steve Easterbrook. This presentation is available free for non-commercial use with attribution under a creative commons license.
21
University of Toronto
Types of Generalizations
Adapted from chapter 5 of Atzeni et al, Database Systems McGraw Hill, 1999
Total generalizations:
every instance of the parent
entity is an instance of one of
its children
Shown as a solid arrow
(otherwise: Partial, shown as an
unfilled arrow)
Exclusive generalizations:
every instance of the parent
entity is at most an instance of
one of its children
(otherwise: overlapping)
2004-5 Steve Easterbrook. This presentation is available free for non-commercial use with attribution under a creative commons license.
22
University of Toronto
Adapted from chapter 5 of Atzeni et al, Database Systems McGraw Hill, 1999
2004-5 Steve Easterbrook. This presentation is available free for non-commercial use with attribution under a creative commons license.
23
University of Toronto
2004-5 Steve Easterbrook. This presentation is available free for non-commercial use with attribution under a creative commons license.
24