Chapter - Seven: The Relational Algebra and Relational Calculus
Chapter - Seven: The Relational Algebra and Relational Calculus
Fn Lname fn lname
1. STUDENT ∪ INSTRUCTOR
2. STUDENT ꓵ INSTRUCTOR
3. STUDENT − INSTRUCTOR
4. INSTRUCTOR − STUDENT.
Example 2. from the relation r and s
The CARTESIAN PRODUCT (CROSS PRODUCT) Operation
is also a binary set operation, but the relations on which it is applied
do not have to be union compatible.
In its binary form, this set operation produces a new element by
combining every member (tuple) from one relation (set) with every
member (tuple) from the other relation (set).
In general, the result of R(A1, A2, ..., An) × S(B1, B2, ..., Bm) is a
relation Q with degree n + m attributes Q(A1, A2, ..., An, B1, B2, ...,
Bm), in that order.
The resulting relation Q has one tuple for each combination of
tuples—one from R and one from S.
if R has n R tuples (denoted as |R| = nR), and S has nS tuples,
then R × S will have nR * nS tuples.
Cont …
The CARTESIAN PRODUCT creates tuples with the combined
attributes of two relations. We can SELECT related tuples only
from the two relations by specifying an appropriate selection
condition after the Cartesian product.
In SQL, CARTESIAN PRODUCT can be realized by using the
CROSS JOIN option in joined tables . Alternatively, if there are
two tables in the WHERE clause and there is no corresponding
join condition in the query, the result will also be the
CARTESIAN PRODUCT of the two tables.
Example 1.
For example, suppose that we want to retrieve a list of names
of each female employee’s dependents. We can do this as
follows:
FEMALE_EMPS ← σSex=‘F’(EMPLOYEE)
EMPNAMES ← π Fname, Lname, Ssn(FEMALE_EMPS)
EMP_DEPENDENTS ← EMPNAMES × DEPENDENT
ACTUAL_DEPENDENTS ←
σSsn=Essn(EMP_DEPENDENTS)
RESULT ← πFname , Lname,
Dependent_name(ACTUAL_DEPENDENTS)
Cont.
The EMP_DEPENDENTS relation is the result of applying
the CARTESIAN PRODUCT operation to EMPNAMES .
In EMP_DEPENDENTS, every tuple from EMPNAMES is
combined with every tuple from DEPENDENT, giving a
result that is not very meaningful (every dependent is
combined with every female employee).
We want to combine a female employee tuple only with her
particular dependents—namely, the DEPENDENT tuples
whose Essn value match the Ssn value of the EMPLOYEE
tuple.
The ACTUAL_DEPENDENTS relation accomplishes this.
Example 2. given the relations r and s
END OF CLASS DAY