The Entity-Relationship Model
The Entity-Relationship Model
The Entity-Relationship Model
The EntityRelationship
Model
R &G - Chapter 2
Enrolled
sid
53666
53666
53650
53666
ER Model Basics
cid
nam
essn
lot
Employees
Carnatic101
Reggae203
Topology112
History105
Students
grade
sid
name
C
B
A
B
login
age
gpa
Conceptual Design
3.2
3.8
ER Model Basics
(Contd.)
since
name
ssn
dname
did
lot
budget
Works_In
3.4
Employees
Departments
name
name
ER Model Basics
(Cont.)
ssn
Key
Constraints
lot
since
ss n
lot
Employees
dname
did
Manages
budget
Departments
Employees
rsupe
visor
since
dname
budget
did
Departments
s
ubord inate
Works_In
lot
did
budget
since
Manages
Many-toMany
1-to Many
1-to-1
Departments
Em ployees
Works_In
since
Weak Entities
Participation Constraints
Does every employee work in a department?
If so, this is a participation constraint
the participation of Employees in Works_In is said
to be
total (vs. partial)
What if every department has an employee
working in it?
name
dname
Basically means
at least one
ssn
An employee
can work in
many
departments; a
dept can have
Inmany
contrast, each
dept
has at most
employees.
one manager,
according to the
key constraint on
Manages.
name
lot
cost
pname
age
Works_In
Means: exactly
one
since
Policy
Employees
Dependents
name
ssn Employees
lot
pname
Bad
design
ssn
name
age
Covers
Dependents
Policies
policyid
cost
pname
lot
age
Dependents
Employees
Purchaser
Better
design
Beneficiary
Policies
policyid
cost
Summary so far
Binary vs. Ternary Relationships
(Contd.)
qty
Parts
Contract
Departments
Suppliers
Parts
VS
.
Departments
needs
can-supply
Suppliers
deals-with
S can-supply P, D needs P, and D dealswith S does not imply that D has agreed to
buy P from S.
How do we record qty?
Aggregati
on
ssn
lot
Employees
Used to model
a relationship
involving a
relationship
set.
name
Monitors
until
since
started_on
pid
pbudget
did
dname
budget
Sponsors
Departments
Projects
Allows us to treat
a relationship
Aggregation vs. ternary
participation
set as an entityrelationship?
in
(other)
set for
Monitors is a distinct relationship,
relationships
purposes of with a descriptive attribute.
.
Also, can say that each sponsorship
is
monitored by at most one employee.
ssn
Works_In2 does
not allow an
employee to work
in atwo
department
for
or more
periods.
Similar to the problem
of wanting to record
several addresses for
an employee: we want
to record several
values of the
descriptive attributes
for each instance of
this relationship.
to
lot
Works_In2
Employees
ssn
dname
did
budget
Departments
name
lot
Employees
did
Works_In3
dname
budget
Departments
to
from
Dur tion
a
Entity vs.
Relationship
OKseparate
as long as a
manager gets
discretionary
a
budget
dept.
What if managers
dbudget covers
all managed
depts?
(can repeat value,
but
such
redundancy
is
problematic)
since
name
ssn
dbudget
lot
Employees
dname
budget
did
Departments
Manages2
name
ssn
lot
dname
did
Employees
budget
Departments
is_manager
apptnum
managed_by
since
Mgr_Appts
dbudget
Converting ER to Relational
Logical DB Design: ER to
Relational
ssn
Entity sets to
tables.
But many simple concepts in ER are
subtle to specify in relations
ssn
lot
name
lot
123-22-3666 Attishoo
48
231-31-5368 Smiley
22
131-24-3650 Smethurst 35
Employees
123-22-3666
231-31-5368
56
51
3/3/93
2/2/92
since
Manages
did
bu
Depar
tments
dname
dget
did INTEGER,
budget REAL,
ssn CHAR(11),
since DATE,
PRIMARY KEY (did),
FOREIGN KEY (ssn)
REFERENCES
Employees)
Review: Key
Constraints
most one
Each dept has at
manager,
according to
the key
constraint on
Manage
s.
since
name
dname
ssn
lot
did
budget
Employees
Manages
Departments
Translation to
relational
model?
1-to-1
1-to Many
Many-to-1
Many-to-Many
Manages
Em ployees
Departments
Works_In
since
Dependents
Summary of ER (Cont.)
Several kinds of integrity constraints:
key constraints
participation constraints
Some foreign key constraints are also
implicit in the definition of a relationship
set.
Many other constraints (notably,
functional dependencies) cannot be
expressed.
Constraints play an important role in
determining the best database design for
an enterprise.
Summary of ER (Cont.)
ER design is subjective. There are often many
ways to model a given scenario!
Analyzing alternatives can be tricky, especially for
a large enterprise. Common choices include:
Entity vs. attribute, entity vs. relationship, binary
or n- ary relationship, whether or not to use ISA
hierarchies, aggregation.
Ensuring good database design: resulting
relational schema should be analyzed and
refned further.
Functional
Dependency
information
and
normalization techniques are especially useful.