M2-Relational Algebra
M2-Relational Algebra
SELECT operation is used to select a subset of the tuples from a relation that
satisfy a selection condition. It is a filter that keeps only those tuples that
satisfy a qualifying condition – those satisfying the condition are selected
while others are discarded.
Example: To select the EMPLOYEE tuples whose department number is
four or those whose salary is greater than $30,000 the following notation is
used:
DNO = 4 (EMPLOYEE)
SALARY > 30,000 (EMPLOYEE)
In general, the select operation is denoted by <selection condition>(R) where the
symbol (sigma) is used to denote the select operator, and the selection
condition is a Boolean expression specified on the attributes of relation R
The general form of the project operation is <attribute list>(R) where
(pi) is the symbol used to represent the project operation and <attribute list>
is the desired list of attributes from the attributes of relation R.
The project operation removes any duplicate tuples, so the result of the
project operation is a set of tuples and hence a valid relation.
– ( <list2> (R) ) =
<list1> <list1> (R) as long as <list2> contains
the attributes in <list2>
STUDENTINSTRUCTOR
Example: The result of the intersection operation (figure below) includes only
those who are both students and instructors.
STUDENT INSTRUCTOR
Example: The figure shows the names of students who are not instructors, and
the names of instructors who are not students.
STUDENT-INSTRUCTOR
INSTRUCTOR-STUDENT
DIVISION Operation
– The division operation is applied to two relations
R(Z) S(X), where X subset Z. Let Y = Z - X (and hence Z
= X Y); that is, let Y be the set of attributes of R that are
not attributes of S.
DNOEMPLOYEEEMPLOYEE)
EMPS_WITH_DEPS(SSN) ESSN(DEPENDENT)
EMPS_WITHOUT_DEPS (ALL_EMPS - EMPS_WITH_DEPS)
RESULT LNAME, FNAME (EMPS_WITHOUT_DEPS * EMPLOYEE)
Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition Slide 4 -40
Copyright © 2004 Ramez Elmasri and Shamkant Navathe
Relational Calculus
A relational calculus expression creates a new relation, which is
specified in terms of variables that range over rows of the stored
database relations (in tuple calculus) or over columns of the
stored relations (in domain calculus).
Example: To find the first and last names of all employees whose salary is above
$50,000, we can write the following tuple calculus expression:
Query :
{uv | ( q) ( r) ( s) ( t) ( w) ( x) ( y) ( z)
(EMPLOYEE(qrstuvwxyz) and q=’John’ and r=’B’ and s=’Smith’)}
Ten variables for the employee relation are needed, one to range over the
domain of each attribute in order. Of the ten variables q, r, s, . . ., z, only u and
v are free.
Specify the requested attributes, BDATE and ADDRESS, by the free domain
variables u for BDATE and v for ADDRESS.
Specify the condition for selecting a tuple following the bar ( | )—namely, that
the sequence of values assigned to the variables qrstuvwxyz be a tuple of the
employee relation and that the values for q (FNAME), r (MINIT), and s
(LNAME) be ‗John‘, ‗B‘, and ‗Smith‘, respectively.