Professional Documents
Culture Documents
Lecture3-The Relational Model
Lecture3-The Relational Model
Essam Mansour
Today…
Last Session:
The entity relationship (ER) model
Today’s Session:
ER model (Cont’d): conceptual design choices
The relational model
Basic Constructs of the relational model
Basic SQL
2
Participation Constraints
Consider again the “Employees” and “Departments” entity sets as well as the
“Manages” relationship set
Should every department have a manager?
If so, this is a participation constraint
Such a constraint entails that every Departments entity must appear in an
instance of the Manages relationship
The participation of Departments in Manages is said to be total (vs. partial)
since
name dname
ssn lot did budget
4
Total vs. Partial Participations
5
Total vs. Partial Participations
6
Weak Entities
A weak entity can be identified uniquely only by considering
the primary key of another (owner) entity
Owner entity set and weak entity set must participate in a one-
to-many relationship set (one owner, many weak entities)
Weak entity set must have total participation in this
identifying relationship set
7
Weak Entities: An Example
“Dependents” has no unique key of its own
“Dependents” is a weak entity with partial key “pname”
“Policy” is an identifying relationship set
“pname” + “ssn” are the primary key of “Dependents”
name
ssn lot
Hourly_Emps Contract_Emps
9
Overlap and Covering Constraints
Overlap constraints A
Can an entity belong to
both ‘B’ and ‘C’?
Covering constraints
B C
Can an ‘A’ entity belong
to neither ‘B’ nor ‘C’?
10
Overlap Constraints: Examples
Overlap constraints A
Can John be in Hourly_Emps and
Contract_Emps? Intuitively, no
11
Covering Constraints: Examples
Covering constraints A
Does every one in Employees
belong to a one of its subclasses?
Intuitively, no
13
Outline
14
Conceptual Design Choices
Should a concept be modeled as an entity or an attribute?
16
Entity vs. Attribute (Cont’d)
Consider the following ER diagram:
from to
name dname
ssn lot did budget
from Duration to 17
Entity vs. Relationship
Consider the following ER diagram, whereby a manager gets a separate
discretionary budget for each department
since dbudget
name dname
ssn lot did budget
policyid cost
19
Binary vs. Ternary Relationships
name
ssn lot pname age
policyid cost
Bad design!
Key constraint on Policies would mean policy can only cover 1 dependent!
20
Binary vs. Ternary Relationships
name pname age
ssn lot
Dependents
Employees
If each policy is
owned by just 1 Purchaser
Beneficiary
employee:
Policies
policyid cost
Better design!
21
Binary vs. Ternary Relationships
But sometimes ternary relationships cannot
be replaced by a set of binary relationships
22
Binary vs. Ternary Relationships
But sometimes ternary relationships cannot
be replaced by a set of binary relationships
qty
Parts Departments
Suppliers
can-supply
Suppliers deals-with
23
Binary vs. Ternary Relationships
But sometimes ternary relationships cannot
be replaced by a set of binary relationships
qty
Parts Departments
Suppliers
can-supply
Suppliers deals-with
24
Binary vs. Ternary Relationships
But sometimes ternary relationships cannot
be replaced by a set of binary relationships
qty
Part Department
Supplier
can-supply
Supplier deals-with
Why is it bad?
25
Binary vs. Ternary Relationships
But sometimes ternary relationships cannot
be replaced by a set of binary relationships
S “can-supply” P,
D “needs” P, and D
“deals-with” S do not VS.
imply that D
has agreed to buy P Parts Departments
from S
can-supply
How do we record Suppliers deals-with
qty?
Why is it bad?
26
ER Model: Summary
Conceptual design follows requirements analysis
Yields a high-level description of data to be stored
28
ER Model: Summary
ER design is subjective
There are often many ways to model a given scenario!
30
Why Studying the Relational Model?
Most widely used model
Vendors: IBM/Informix, Microsoft, Oracle, Sybase, etc.
32
Basic Constructs
The main construct in the relational model is the relation
Textbook:
Raghu Ramakrishnan and Johannes Gehrke,
"Database Management Systems", Third Edition,
McGraw-Hill, download it here
Read Chapter 1 and 2
36
Next Class
37