Académique Documents
Professionnel Documents
Culture Documents
Physical DB design
ER Model Basics
ssn
name
lot
Employees
ER Model Basics
ssn
name
lot
Employees
name
ssn
lot
Employees
Employees
since
name
dname
did
Works_In
lot
budget
Departments
supervisor
subordinate
Reports_To
Key Constraints
since
name
ssn
Consider
Works_In: An
employee can
work in many
departments; a
dept can have
many employees.
In contrast, each
dept has at most
one manager,
according to the
key constraint on
Manages.
dname
lot
Employees
1-to-1
1-to Many
did
Manages
Many-to-1
budget
Departments
Many-to-Many
Example ER
Department
major
An ER diagram
represents several
assertions about the
real world. What are
they?
When attributes are
added, more
assertions are made.
How can we ensure
they are correct?
A DB is judged correct
if it captures ER
diagram correctly.
faculty
Professor
advisor
offers
Courses
teaches
enrollment
Students
Exercises
Department
major
Is double major
allowed?
Can a student have
more than 1 advisor?
Is joint appointment of
faculty possible?
Can two profs share to
teach the same course?
Can a professor teach
more than one course?
Can a professor stay
without affiliated with a
department?
faculty
Professor
advisor
offers
Courses
teaches
enrollment
Students
Participation Constraints
Does every department have a manager?
ssn
dname
did
lot
Employees
Manages
budget
Departments
Works_In
since
10
Weak Entities
A weak entity can be identified uniquely only by
considering the primary key of another (owner) entity.
lot
Employees
cost
Policy
pname
age
Dependents
11
name
ssn
lot
Employees
hours_worked
ISA
contractid
Hourly_Emps
Contract_Emps
ssn
Aggregation
Used when we
have to model a
relationship
involving (entitity
sets and) a
relationship set.
Aggregation
allows us to treat a
relationship set as
an entity set for
purposes of
participation in
(other)
relationships.
name
lot
Employees
Monitors
since
started_on
pid
pbudget
Projects
until
dname
did
Sponsors
budget
Departments
from
name
ssn
to
lot
did
Works_In4
Employees
ssn
name
dname
lot
Employees
from
budget
Departments
did
Works_In4
Duration
dname
budget
Departments
to
16
Redundancy: dbudget
stored for each dept
managed by manager.
Misleading: Suggests
dbudget associated
with department-mgr
combination.
since
name
ssn
dbudget
lot
Employees
did
dname
budget
Departments
Manages2
name
ssn
lot
since
Employees
ISA
Managers
Manages2
dbudget
dname
did
budget
Departments
If each policy is
owned by just 1
employee, and
each dependent
is tied to the
covering policy,
first diagram is
inaccurate.
What are the
additional
constraints in
the 2nd
diagram?
name
pname
lot
Employees
Policies
policyid
ssn
name
Dependents
Covers
Bad design
age
cost
pname
lot
age
Dependents
Employees
Purchaser
Beneficiary
Better design
policyid
Policies
cost
18
19
Summary of Conceptual
Design
20
Summary of ER (Contd.)
Several kinds of integrity constraints can be
expressed in the ER model: key constraints,
participation constraints, and overlap/covering
constraints for ISA hierarchies. Some foreign
key constraints are also implicit in the
definition of a relationship set.
Summary of ER (Contd.)
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:
Exercise
ssn
name
CustAcct
Customer
ssn
name
acct#
addr
balance
Account
lot
Employees
Manages
Dept
deptid
budget
23
Design Exercise
Design a DB using ER, and sketch the resulting diagram.
State any important assumptions you made in reaching
the design. Show explicitly whether relationships are 1-1,
1-M, or N-M.
UVA registrars office: It maintains data about each
class, including the instructor, students, enrollment,
time and place of the class meetings. For each studentclass pair, a grade is recorded.
Hospital: It maintains all patients visited, including age
and address. It also keeps track of the information
about billing, visits, data, reason for visit, and
treatment.
24