Chapter 8: Foundations of Relational Implementation

Download Report

Transcript Chapter 8: Foundations of Relational Implementation

Relational Algebra
MBAD 613
R. Nakatsu
Relational Data Manipulation
Language
•
•
•
•
Query-by-Example; Query-by-Form
Transform-Oriented Languages
Relational Algebra
Relational Calculus
DML Interfaces
• Forms
• Query Language Interface
SELECT Name, Age
FROM PATIENT
WHERE Physician = ‘Levy’
© 2000 Prentice Hall
Domain Definitions
© 2000 Prentice Hall
Domain Compatibility
Two domains are domain compatible if
1) they have the same number of attributes and
2) each corresponding attribute has the same domain.
Page 204
Attribute Domains
© 2000 Prentice Hall
Relational Operators
1.
2.
3.
4.
5.
6.
7.
8.
Union (A U B or A + B)
Difference (A – B)
Intersection (A ∩ B)
Projection
Selection
Product (A X B)
Join (equijoiin, outer join)
Division (A / B)
1. Union
Adding tuples from one relation A to
those of a second B. Denoted A + B or
A U B. A and B must be domain
compatible.
© 2000 Prentice Hall
2. Difference
Includes tuples that occur in the first
relation A but not the second B.
Denoted A - B. A and B must be
domain compatible.
© 2000 Prentice Hall
3. Intersection
Includes tuples that are in both the
first relation A and the second
relation B. Denoted A ∩ B. A and B
must be domain compatible.
© 2000 Prentice Hall
4. Projection
Selects specified attributes (columns)
from a relation”
© 2000 Prentice Hall
5. Selection
Selects tuples (rows) from a relation.
© 2000 Prentice Hall
6. Product
The product of two relations
(sometimes called the Cartesian
Product) is the concatenation of
every tuple of one relation A with
every tuple of a second relation B.
Denoted A X B
7. Join
The join operator allows us to combine
information from two or more tables.
It is a combination of the product, selection,
and (possibly) projection operations.
Two basic types:
- equijoin: includes only matched pairs
– outer join: the unmatched pairs are
retained, and the values are left null.
Equijoin, Natural, Left Outer
© 2000 Prentice Hall
8. Division
Find those values in the first relation A
that are related to all of the values in
the second relation B.
Denoted A / B
Example: Division
AB
a
a1
a1
a2
a3
a3
a3
B
b
b1
b2
b2
b1
b2
b3
What is AB / B?
b
b1
b2
Example Data
Student
Enroll
Course