CS 220P
Conceptual Modeling of Data�(Lecture 3)
Prof. Sharad Mehrotra
Information and Computer Science Department, University of California at Irvine
1
Last Class….underneath the hood
File system
Buffer manager
record-oriented file system
indexing
query optimization
query processor
query optimization
transactions
..
…
2
Next few weeks…
Programming with databases
3
Database Design Process
4
high level specs
conceptual schema
logical schema
(in DBMS model)
miniworld
conceptual design
logical design
physical design
functional analysis
application design
transaction implementation
Data requirements
functional requirements
application programs
Physical schema
Requirement Analysis
Functional Design
Database Design
Database design often starts by specifying a schema in ER diagrams.
ER Diagrams
5
Entities and Entity Sets
6
Attributes
7
Relationships
8
259 10000
245 2400
364 200000
305 20000
customer
account
Cust-Account Relationship set
62900 main austin
62901 north urbana
Sam
Pat
Visualizing ER Relationships as a Table
9
Relationship Set Corresponding to the Relationship Cust-Account
Row in the table represents the pair of entities participating in the relationship
Customer | Account# |
John | 1001 |
Megan | 1001 |
Megan | 2002 |
ER Diagram -- graphical representation of ER schema
10
cust_acct
opening date
Customer
ssn
name
street
city
Account
account number
balance
Roles in a Relationship
11
employee
works for
Manager
Employee
Constraints on Entity Sets
12
Constraints on Entity Sets (cont.)
13
Cardinality Constraints on Relationship Sets
14
Cardinality Constraints on Relationship Sets (cont.)
15
Multiplicity of Relationships
16
Many-to-one
One-to-one
Many-to-many
Multiplicity of relationship in ER diagram represented by an arrow pointing to “one”
Many to Many Relationship
17
customer
cust_acct
account
opening date
legal
legal
Many to One Relationship
18
Illegal
legal
customer
custacct
account
opening date
Relationship Attribute in a Many to One Relationship
19
customer
custacct
account
opening date
custacct
account
Customer
ssn
name
street
city
opening-date
One to One Relationship
20
Illegal
Illegal
Legal
customer
custacct
account
opening date
Other notations for Cardinality constraints
21
customer
custacct
account
opening date
N
M
Participation Constraints
22
Participation Constraints
23
Example
24
borrower
Belongs-to
Customer-of
Customer
ssn
name
Loans
loanid
amount
Branch
branchid
location
Weak Entity Sets
25
Weak Entity Sets (cont.)
26
cust_acct
opening date
log
customer
ssn
name
street
city
account
account number
balance
transaction
trans#
A Chain of Weak Entity Sets
27
city
state
street
Located in
Example illustrating that a weak entity set might itself participate as owner in an identifying relationship with another weak entity set.
Located in
A Weak Entity Set with Multiple Owner Entity Sets
28
review
rating
movie
title
reviewer
name
Multiway Relationships
29
CAB Relationship Set
customer
social-security
branch
branchName
account
acct#
balance
CAB
Cardinality Constraint over Multiway Relationships
30
Many to Many to 1 relationship
Illegal: Megan has account 1001 at 2 branches
Legal
CAB
customer
social-security
branch
branchName
account
acct#
balance
Cardinality Constraint over Multiway Relationships
31
Many to 1 to 1 relationship
Illegal: Megan has 2 accounts in Tokyo Branch
Legal
CAB
customer
social-security
branch
branchName
account
acct#
balance
Cardinality Constraint over Multiway Relationships
32
1 to 1 to 1 relationship
Illegal: Both John and Megan have account 1002 in Tokyo Branch
Legal
CAB
customer
social-security
branch
branchName
account
acct#
balance
Limitations of the Basic ER Model Studied So Far
33
How do we represent the above in ER model?
Possible Solutions
34
Subclass/Superclass Relationships
35
IS A
account
acct#
balance
checking
overdraft-amount
savings
interest-rate
Types of Class/Subclass Relationships
36
Superclass/Subclass Lattice
37
person
employee
alumnus
student
staff
faculty
student
assistant
grad
undergrad
RA
TA
d
o
ISA
ISA
ISA
IS A
d
o
Overlapping means that a person can be both a employee and an alumnus for example
ISA
Superclass/Subclass Lattice
38
person
employee
alumnus
student
staff
faculty
student
assistant
grad
undergrad
RA
TA
d
o
ISA
ISA
ISA
IS A
d
o
ISA
Disjoint means that employees either are staff, or faculty, or student assistants but cannot more than 1. Also, total participation means that every employee is either one of these three
Superclass/Subclass Lattice
39
person
employee
alumnus
student
staff
faculty
student
assistant
grad
undergrad
RA
TA
d
o
ISA
ISA
ISA
IS A
d
o
ISA
If we have only a single subclass we can draw or not draw a is-a relationship. It is implied.
Superclass/Subclass Lattice
40
person
employee
alumnus
student
staff
faculty
student
assistant
grad
undergrad
RA
TA
d
o
ISA
ISA
ISA
IS A
d
o
ISA
Student class is classified based on two different is-a relationships.
They are classified as grad and undergrad. And the second classification is that some of the students are also assistants. Note that student assistants can be either grad or undergrad.
Superclass/Subclass Lattice
41
person
employee
alumnus
student
staff
faculty
student
assistant
grad
undergrad
RA
TA
d
o
ISA
ISA
ISA
IS A
d
o
ISA
Student assistant class inherits its attributes and relationships from both the employee and also from the student classes. This is multiple inheritance.
Multiple Inheritance
42
Superclass/Subclass Lattice
43
person
employee
alumnus
student
staff
faculty
student
assistant
grad
undergrad
RA
TA
d
o
ISA
ISA
ISA
IS A
d
o
ISA
Question: Could person classification into employee, alumnus, and students have been a disjoint ?
Limitations of ER Model
44
employee
project
tools
works_using
employee
project
tools
work
using
relationships among relationships not permitted in ER!
incorrect since it requires each project to use tools
Aggregation
45
employee
project
tools
works
using
N
N
Representation without Aggregation in ER Model
46
employee
project
tools
works
using
employee
project
tools
EP
redundant relationship!
works
using
awkward schema!
Review of ER Model
47
Database Design
48
Schema Design Issues
49
E/R Design Principles
50
Redundant Attributes
51
manages
start date
department
dept#
mgr start date
employee
emp-ssno
Redundant Relationship
52
supplier
project
item
supplies
used-by
is-customer-of
A Design Problem
53
Uniqueness assumptions
54
Design 1: Bad design
55
Located-in2
capital
County Population repeated for each city
cities
county-name
county-population
city-name
city-population
states
name
population
Design 2: Good design
56
Located-in2
capital
County Population repeated for each city
cities
city-name
city-population
states
name
population
counties
county-name
county-population
Belongs-to
Another Design Problem
57
Design 1: Bad design
58
Does not capture the constraints that express trains only stop only at express stations and local trains stop at all local stations
trains
number
type
engineer
stations
name
type
address
StopsAt
time
Design 1: Better design
59
trains
number
engineer
stations
name
address
StopsAt1
time
IsA
express train
local train
express stop
local stop
IsA
d
d
StopsAt2
time