Академический Документы
Профессиональный Документы
Культура Документы
ER to Relational
Mappings
R&G Chapters 2, 3
Lecture 22
Administrivia
Homework 4 Due Tuesday
Today: More on the ER Model & DB Design
Next week: Concurrency Control &
Recovery
lot
Employees
cost
Policy
pname
age
Dependents
name
ssn
As
in Java, attributes
inherited.
If we declare A ISA B,
every A entity is also
considered to be a B
entity.
lot
Employees
hourly_wages
hours_worked
ISA
Hourly_Emps
contractid
Contract_Emps
Aggregation
ssn
name
Employees
lot
Used to model a
relationship
Monitors
until
involving a
relationship set.
since
started_on
Allows us to treat
dname
pid
pbudget
did
budget
a relationship
set as an entity
Sponsors
Departments
Projects
set for purposes
of participation Aggregation vs. ternary
in (other)
relationship?
relationships. Monitors is a distinct
relationship, with a descriptive
attribute.
name
ssn
to
lot
did
Works_In2
Employees
ssn
name
dname
lot
Employees
from
budget
Departments
did
Works_In3
Duration
dname
budget
Departments
to
since
name
ssn
dbudget
lot
Employees
did
dname
budget
Departments
Manages2
name
ssn
lot
dname
did
Employees
budget
Departments
is_manager
apptnum
managed_by
since
Mgr_Appts
dbudget
ssn
ssn
name
Employees
lot
name
lot
123-22-3666 Attishoo
48
231-31-5368 Smiley
22
131-24-3650 Smethurst 35
CREATE TABLE
Employees
(ssn CHAR(11),
name CHAR(20),
lot INTEGER,
PRIMARY KEY
name
ssn
did
lot
Employees
dname
Works_In
budget
Departments
name
ssn
budget
did
lot
Employees
dname
Works_In
Departments
did
51
56
51
since
1/1/91
3/3/93
2/2/92
name
ssn
dname
lot
Employees
did
Manages
budget
Departments
Translation to
relational model?
1-to-1
1-to Many
Many-to-1
Many-to-Many
since
name
ssn
lot
Employees
Two approaches:
Map relationship set
to a table:
Note that did is the
key now!
Separate tables for
Employees and
Departments.
Since each
department has a
unique manager, we
could instead
combine Manages
and Departments.
dname
did
Manages
budget
Departments
Employees,
FOREIGN KEY (did) REFERENCES
CREATE
TABLE Dept_Mgr(
Departments)
did INTEGER,
dname CHAR(20),
budget REAL,
mgr_ssn CHAR(11),
since DATE,
PRIMARY KEY (did),
FOREIGN KEY (mgr_ssn) REFERENCES
Employees (ssn))
did
lot
Employees
Manages
Works_In
since
budget
Departments
lot
Employees
cost
Policy
pname
age
Dependents
Employees,
name
lot
Employees
hourly_wages
hours_worked
ISA
As
Hourly_Emps
contractid
Contract_Emps
qty
Parts
Contract
Suppliers
Departments
Summary of ER (Cont.)
Several kinds of integrity constraints:
key constraints
participation constraints
overlap/covering for ISA hierarchies.
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.
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 refined further.
Functional Dependency information and normalization
techniques are especially useful.