Er Model
Er Model
Prof. S. Mehrotra
Information and Computer Science
Department
University of California at Irvine
Outline
Database design process
Entity/Relationship Model
Entity sets
Relationship sets
Constraints on entity sets
Constraints on relationship sets
Weak entity sets
Superclass/subclass relationships
Aggregation
Good Design Principles
Examples
Conceptual Database Design
ODL C++
C++ based
Embedding
OODBMSs
ODL Smalltalk
Embedding
Abstract ODL
Smalltalk based
OODBMSs
Relations
E/R
Relational DBMSs
Ideas and
information
259 10000
sam 62900 main austin
305 20000
364 200000
Visualizing ER Relationships as a
Table
opening date
worker
Constraints on Entity Sets
Key Constraint:
With each entity set a notion of a key can be associated.
A key is a set of attributes that uniquely identify an entity in entity
set.
Examples:
designer may specify that {ssno} is a key for a entity set customer
entity with attributes {ssno, accountno, balance, name, address}
designer may specify that {accountno} is also a key , that is, no joint
accounts are permitted.
Denoted in ER diagram by underlining the attributes that form a key
multiple keys may exist in which case one chosen as primary key
and underlined. Other keys called secondary keys either not
indicated or listed in a side comment attached to the diagram.
Constraints on Entity Sets (cont.)
Domain constraint:
with each simple attribute a domain is associated. The
value of the attribute for each entity is constrained to be in
the domain.
Cardinality Constraints on
Relationship Sets
Consider binary relationship set R between entity sets A
and B
One to one: an entity in A is associated with at most
one entity in B, and an entity in B is associated with
atmost one entity in A.
an employee has only one spouse in a married-to relationship.
Many to One: An entity in A is associated with at most
one entity in B, an entity in B is associated with many
entities in A.
an employee works in a single department but a department
consists of many employees.
Cardinality Constraints on
Relationship Sets (cont.)
opening date
opening date
Illegal legal
opening date
opening date
One to One Relationship
opening date
Illegal
Customer Account Start Date
1 customer can have 1 John 1001 Jan 20th 1999
account. Megan 1001 March 16th 1999
N N
customer borrower loans
N
N
Belongs-to
1
N
Customer-of branch
opening date
log
reviewer
rating
name
Reviewers review movie and assign a rating -- thumb
up/thumbs down.
Review is a weak entity set whose owner sets correspond
to both the movie and the reviewer entity sets.
Key for the review entity set = key of movie + key of
reviewer
Multiway Relationships
Usually binary relationships (connecting two E.S.) suffice.
However, there are some cases where three or more E.S. must be
connected by one relationship.
Similar to binary relationship, cardinality and participation
constraints defined over multiway relationships
Customer Account Branch
branchName John 1001 Irvine
Megan 1001 LA
key
Megan 2001 Tokyo
key
branch
social- acct#
security CAB Relationship Set
balance
Cardinality Constraint over
Multiway Relationships
branchName
key
key branch
social- Customer Account branch
security acct#
John 1001 Irvine
CAB account Megan 1001 Dallas
customer
Megan 1002 Tokyo
Megan 1003 Tokyo
Many to1 to 1 relationship balance
Illegal: Megan has 2 accounts
in Tokyo Branch
Interpretation:
Customer Account branch
Each (customer, branch) related John 1001 Irvine
to a single account Megan 1001 Dallas
Each (customer, account) pair Megan 1002 Tokyo
related to a single branch John 1002 Tokyo
Legal
Cardinality Constraint over
Multiway Relationships
branchName
key
Customer Account branch
key branch John 1001 Irvine
social-
security acct# Megan 1001 Dallas
Megan 1002 Tokyo
customer CAB account John 1002 Tokyo
Illegal: Both John and
1 to1 to 1 relationship balance Megan have account 1002 in
Tokyo Branch
Interpretation:
Each (customer, branch) related to a single account
Each (customer, account) pair related to a single
branch
Customer Account branch
Each (branch, account) pair can have single John 1001 Irvine
customer Megan 1001 Dallas
Megan 1002 Tokyo
Legal
Representing Ternary Relationship
Using Binary Relationships
branch
branch
customer
customer CAB account
CB
AB
Customer Account branch
C2 A1 B1
C1 A2 B1 customer CA account
C1 A1 B2
branch
C’ B’ A’
customer
customer CAB account
customer
customer CAB account
customer
customer CAB account
branch
customer
customer CAB account
balance
ISA
savings checking
o
ISA
d
ISA d ISA
o
ISA
RA TA
Multiple Inheritance
In a class/subclass relationship, the subclass inherits all its
attributes from the superclass.
If a subclass has 2 or more superclasses, then subclass
inherits from all the superclasses (multiple inheritance)
How should conflicts be resolved?
Example:
Employee Entity Set: with an attribute country denoting the country
of citizenship
Asians Entity Set: with an attribute country denoting the country
from which a particular person originated.
Asian_Employee Entity set is a subclass of both Employee and
Asians. However, what does country attribute of the
Asian_Employee correspond to.
ER model mute on multiple inheritance
Limitations of ER Model
work
employee project
using
relationships among
relationships not
permitted in ER! tools
Aggregation
employee project
works
using
N
tools
Treat the relationship set work and the entity sets employee and
projects as a higher level entity set-- an aggregate entity set
Permit relationships between aggregate entity sets and other
entity sets
Representation without
Aggregation in ER Model
employee project
works
using
redundant
relationship!
tools
employee project
EP
works using
awkward schema!
tools
Review of ER Model
Basic Model:
Entities : strong, weak
Attributes associated with entity sets and relationships
Relationships: binary, ternary, ...
Role of entity sets in a relationship
Constraints on entity set: domain constraints, key constraint
Constraint on relationships: cardinality -- 1-1, 1-N, M-N,
participation (also called existential) --total vrs partial
Extended Model:
Notion of superclass and subclass
Superclass/subclass relationships: disjoint vrs overlapping, total
vrs partial
Notion of aggregation
E/R Design Cycle
Good design important since schemas do not
change often
The first version is almost always wrong.
Typical Schema Design Cycle
1: Requirement Analysis: Learn about the application.
– what problem does the application solve, what questions does the application ask
about the data, what data does the application need to answer these questions.
2: Design a trial schema
-- top-down strategy: define high level concepts and then use successive
refinements
-- bottom-up strategy: start with schema containing basic abstractions and then
combine or add to them
3: Evaluate schema for quality and completeness.
-- consider the future: how is the application likely to change? Account for
change
4: Iterate until satisfied
Schema Design Issues
Observation: there may be multiple ER schemas
describing the same target database or miniworld.
Decisions that need to be made:
whether to use an attribute or entity set to represent an object
whether to model a concept as a relationship or an entity set
whether to use ternary relationship or a set of binary ones
whether to use a strong entity set of a weak entity set
whether using generalization/specializations is appropriate
whether using aggregates is appropriate
Unfortunately, there are no straightforward answers to
these questions
No two design teams will come up with the same design.
However, there are some simple design principles that
should be followed during ER design.
E/R Design Principles
Schemas should not change often. So store frequently
changing information as instances.
currently each project consists of 10 members. Since later
projects may have more or less employees, do not hard code the
10 employees as 10 attributes of the project entity
Schemas should prevent representing the same facts
multiple times (avoid redundancy).
An attribute/relationship is redundant if deleting it does not
result in a loss of any information
redundancy may cause:
wastage of space in storing data
application programming to be more difficult -- applications need to
update all instances of a fact else risk inconsistency of database
Consistent and clear naming policy for attributes,
entities, and relationships
Redundant Attributes
dept # mgr start date emp ssno
start date
supplies
project
item
used-by
•The fact that a project is-customer-of a supplier can be derived from the
relationships between supplier and item and between item and project.
•That is, a project is-customer-of a supplier if there is a item that the supplier
supplies which is used by the project.
•Redundancy analysis can be tricky -- if supplies is a N:N relationship, then
schema does not contain redundancy.
A Design Problem
We wish to design a database representing
cities, counties, and states in the US.
For states, we wish to record the name,
population, and state capital (which is a city).
For counties, we wish to record the name, the
population, and the state in which it is located.
For cities, we wish to record the name, the
population, the state in which it is located and
the county in which it is located.
Uniqueness assumptions:
Names of states are unique.
Names of counties are only unique within a
state (e.g., 26 states have Washington
Counties).
Cities are likewise unique only within a state
(e.g., there are 24 Springfields among the 50
states).
Some counties and cities have the same name,
even within a state (example: San Francisco).
All cities are located within a single county.
Design 1: Bad design
Popu. name
states
Co. name
Co. Popu.
Located-in2
cities
capital
County Population
Ci. Popu. Ci. name repeated for each city
Design 2 -- good design
Co. Popu.
Co. name Popu. name
Located -
counties states
in1
Belongs-to
cities
capital
Does not capture the constraints that express trains only stop only at express
stations and local trains stop at all local stations
Design 2: Better Design
sname saddress
number engineer
time stations
trains
StopsAt2 d
d IS
IS time A
A
stopsAt1