0% found this document useful (0 votes)
3 views

Module 4

Uploaded by

unknownfanzhou
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Module 4

Uploaded by

unknownfanzhou
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 79

Database Management Systems

CS 5200

Dr. Tehmina Amjad


Spring 2024
Relational Algebra and Relational
Calculus

2
Outline
• Relational Algebra
• Unary Relational Operations
• Relational Algebra Operations From Set Theory
• Binary Relational Operations
• Additional Relational Operations
• Examples of Queries in Relational Algebra
• Relational Calculus
• Tuple Relational Calculus
• Domain Relational Calculus
• Example Database Application (COMPANY)

3
Brief History of Origins of Algebra
• Muhammad ibn Musa al-Khwarizmi (800-847 CE) – from Morocco wrote a book
titled al-jabr about arithmetic of variables
• Book was translated into Latin.
• Its title (al-jabr) gave Algebra its name.

• Al-Khwarizmi called variables “shay”


• “Shay” is Arabic for “thing”.
• Spanish transliterated “shay” as “xay” (“x” was “sh” in Spain).
• In time this word was abbreviated as x.

• Where does the word Algorithm come from?


• Algorithm originates from “al-Khwarizmi"
• Reference: PBS (http://www.pbs.org/empires/islam/innoalgebra.html)

4
Introduction
• Relational algebra is formal language associated with the relational
model.
• Informally, relational algebra is a (high-level) procedural language.

5
Why do weed to focus on Relational algebra?
• Its still relevant even today for many languages that focus on
interacting with data
• Its basis for big data analytical systems that support SQL like
languages
• They have similar concepts and use similar order of execution
• Apache Hive: SQL on Hadoop
• Spark: in memory Hadoop
• Presto: Facebook’s analytical system (SQL like language)
• No-SQL: H Base, Cassandra
• These languages will keep on evolving but their basis on Relational
Algebra is same
6
Relational Algebra
• Relational algebra operations work on one or more relations to define
another relation without changing the original relations.
• Both operands and results are relations, so output from one
operation can become input to another operation.
• A sequence of relational algebra operations forms a relational
algebra expression.
• Allows expressions to be nested, just as in arithmetic. This property is
called closure.

7
Relational Algebra
• Relational Algebra consists of several groups of operations
• Unary Relational Operations
• SELECT (symbol: s (sigma))
• PROJECT (symbol: p (pi))
• RENAME (symbol: r (rho))
• Relational Algebra Operations From Set Theory
• UNION ( È ), INTERSECTION ( Ç ), DIFFERENCE (or MINUS, – )
• CARTESIAN PRODUCT ( x )
• Binary Relational Operations
• JOIN (several variations of JOIN exist)
• DIVISION
• Additional Relational Operations
• OUTER JOINS, OUTER UNION
• AGGREGATE FUNCTIONS (These compute summary of information: for example, SUM, COUNT, AVG, MIN,
MAX)
8
Relational Algebra Operations

9
Relational Algebra Operations

10
Database State for COMPANY
• All examples discussed below refer to the COMPANY database shown here.

11
The following query results refer to this
database state

12
Unary Relational Operations: SELECT
• The SELECT operation (denoted by s (sigma)) is used to select a subset of the tuples from a
relation based on a selection condition.
• The selection condition acts as a filter
• Keeps only those tuples that satisfy the qualifying condition
• Tuples satisfying the condition are selected whereas the other tuples are discarded
(filtered out)
• Examples:
• Select the EMPLOYEE tuples whose department number is 4:
s DNO = 4 (EMPLOYEE)
• Select the employee tuples whose salary is greater than $30,000:
s SALARY > 30,000 (EMPLOYEE)
13
Unary Relational Operations: SELECT
• In general, the select operation is denoted by s <selection condition>(R)
where
• the symbol s (sigma) is used to denote the select operator
• the selection condition is a Boolean (conditional) expression specified on the attributes
of relation R
• tuples that make the condition true are selected
• appear in the result of the operation
• tuples that make the condition false are filtered out
• discarded from the result of the operation

14
Unary Relational Operations: SELECT
• SELECT Operation Properties
• The SELECT operation s <selection condition>(R) produces a relation S that has the
same schema (same attributes) as R
• SELECT s is commutative:
• s <condition1>(s < condition2> (R)) = s <condition2> (s < condition1> (R))
• Because of commutativity property, a cascade (sequence) of SELECT operations
may be applied in any order:
• s<cond1>(s<cond2> (s<cond3> (R)) = s<cond2> (s<cond3> (s<cond1> ( R)))
• A cascade of SELECT operations may be replaced by a single selection with a
conjunction of all the conditions:
• s<cond1>(s< cond2> (s<cond3>(R)) = s <cond1> AND < cond2> AND < cond3>(R)))
• The number of tuples in the result of a SELECT is less than (or equal to) the
number of tuples in the input relation R
15
Unary Relational Operations: SELECT

16
Unary Relational Operations: PROJECT
• PROJECT Operation is denoted by p (pi)
• This operation keeps certain columns (attributes) from a relation and
discards the other columns.
• PROJECT creates a vertical partitioning
• The list of specified columns (attributes) is kept in each tuple
• The other attributes in each tuple are discarded
• Example: To list each employee’s first and last name and salary, the
following is used:
pLNAME, FNAME,SALARY(EMPLOYEE)

17
Unary Relational Operations: PROJECT

• The general form of the project operation is:


p<attribute list>(R)
• p (pi) is the symbol used to represent the project operation
• <attribute list> is the desired list of attributes from relation R.
• The project operation removes any duplicate tuples
• This is because the result of the project operation must be a set of tuples
• Mathematical sets do not allow duplicate elements.

18
Unary Relational Operations: PROJECT
• PROJECT Operation Properties
• The number of tuples in the result of projection p<list>(R) is always less or
equal to the number of tuples in R
• If the list of attributes includes a key of R, then the number of tuples in the result of
PROJECT is equal to the number of tuples in R
• PROJECT is not commutative
• p <list1> (p <list2> (R) ) = p <list1> (R) as long as <list2> contains the attributes in <list1>

19
20
Relational Algebra Expressions
• We may want to apply several relational algebra operations one after
the other
• Either we can write the operations as a single relational algebra expression
by nesting the operations, or
• We can apply one operation at a time and create intermediate result
relations.
• In the latter case, we must give names to the relations that hold
the intermediate results.

21
Single expression versus sequence of
relational operations (Example)
• To retrieve the first name, last name, and salary of all employees who work in
department number 5, we must apply a select and a project operation
• We can write a single relational algebra expression as follows:
• pFNAME, LNAME, SALARY(s DNO=5(EMPLOYEE))
• OR We can explicitly show the sequence of operations, giving a name to each
intermediate relation:
• DEP5_EMPS ¬ s DNO=5(EMPLOYEE)
• RESULT ¬ p FNAME, LNAME, SALARY (DEP5_EMPS)

22
Unary Relational Operations: RENAME
• The RENAME operator is denoted by r (rho)
• In some cases, we may want to rename the attributes of a relation or
the relation name or both
• Useful when a query requires multiple operations
• Necessary in some cases (see JOIN operation later)

23
Unary Relational Operations: RENAME
• The general RENAME operation r can be expressed by any of the
following forms:
• rS (B1, B2, …, Bn )(R) changes both:
• the relation name to S, and
• the column (attribute) names to B1, B1, …..Bn
• rS(R) changes:
• the relation name only to S
• r(B1, B2, …, Bn )(R) changes:
• the column (attribute) names only to B1, B1, …..Bn

24
Unary Relational Operations: RENAME
• For convenience, we also use a shorthand for renaming attributes in an
intermediate relation:
• If we write:
• RESULT ¬ p FNAME, LNAME, SALARY (DEP5_EMPS)
• RESULT will have the same attribute names as DEP5_EMPS (same
attributes as EMPLOYEE)
• If we write:
• RESULT (F, M, L, S, B, A, SX, SAL, SU, DNO)¬ r RESULT (F.M.L.S.B,A,SX,SAL,SU,DNO)
(DEP5_EMPS)
• The 10 attributes of DEP5_EMPS are renamed to F, M, L, S, B, A, SX, SAL,
SU, DNO, respectively
Note: the ¬ symbol is an assignment operator

25
Relational Algebra Operations from
Set Theory: UNION
• UNION Operation
• Binary operation, denoted by È
• The result of R È S, is a relation that includes all tuples that are either in R or
in S or in both R and S
• Duplicate tuples are eliminated
• The two operand relations R and S must be “type compatible” (or UNION
compatible)
• R and S must have same number of attributes
• Each pair of corresponding attributes must be type compatible (have same or
compatible domains)

26
Relational Algebra Operations from
Set Theory: UNION
• Example:
• To retrieve the social security numbers of all employees who either work in department
5 (RESULT1 below) or directly supervise an employee who works in department 5
(RESULT2 below)
• We can use the UNION operation as follows:
DEP5_EMPS ¬ sDNO=5 (EMPLOYEE)
RESULT1 ¬ p SSN(DEP5_EMPS)
RESULT2(SSN) ¬ pSUPERSSN(DEP5_EMPS)
RESULT ¬ RESULT1 È RESULT2
• The union operation produces the tuples that are in either RESULT1 or RESULT2 or both

27
Relational Algebra Operations from
Set Theory: UNION
• UNION Example

STUDENTÈINSTRUCTOR

28
Relational Algebra Operations from
Set Theory: INTERSECTION
• Type Compatibility of operands is required for the binary set operation UNION È,
(also for INTERSECTION Ç, and SET DIFFERENCE –, see next slides)
• R1(A1, A2, ..., An) and R2(B1, B2, ..., Bn) are type compatible if:
• they have the same number of attributes, and
• the domains of corresponding attributes are type compatible (i.e. dom(Ai)=dom(Bi)
for i=1, 2, ..., n).
• The resulting relation for R1ÈR2 (also for R1ÇR2, or R1–R2, see next slides) has
the same attribute names as the first operand relation R1 (by convention)

29
Relational Algebra Operations from Set
Theory: INTERSECTION
• The result of this operation, denoted by R Ç S, is a
relation that includes all tuples that are in both R and S.
• The two operands must be “type compatible”
• Example: The result of the intersection operation (figure
below) includes only those who are both students and
instructors.

STUDENT Ç INSTRUCTOR

30
Relational Algebra Operations from Set
Theory: DIFFERENCE
• Set Difference (or MINUS) Operation
• The result of this operation, denoted by R - S, is a
relation that includes all tuples that are in R but not in
S. The two operands must be "type compatible”.
• 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

31
Some properties of UNION, INTERSECT, and DIFFERENCE

• Notice that both union and intersection are commutative operations; that is
• R È S = S È R, and R Ç S = S Ç R
• Both union and intersection can be treated as n-ary operations applicable to any
number of relations as both are associative operations; that is
• R È (S È T) = (R È S) È T
• (R Ç S) Ç T = R Ç (S Ç T)
• The minus operation is not commutative; that is, in general
• R–S≠S–R

32
Relational Algebra Operations from Set
Theory: CARTESIAN PRODUCT
• CARTESIAN (or CROSS) PRODUCT Operation
• This operation is used to combine tuples from two relations in a combinatorial
fashion.
• Denoted by R(A1, A2, . . ., An) x S(B1, B2, . . ., Bm)
• Result is a relation Q with degree n + m attributes:
• Q(A1, A2, . . ., An, B1, B2, . . ., Bm), in that order.
• The resulting relation state has one tuple for each combination of tuples—one from
R and one from S.
• Hence, if R has nR tuples (denoted as |R| = nR ), and S has nS tuples, then R x S will
have nR * nS tuples.
• The two operands do NOT have to be "type compatible”

33
CARTESIAN PRODUCT

34
CARTESIAN PRODUCT
• We need to find the names of female employees and their dependents
• To keep only combinations where the DEPENDENT is related to the EMPLOYEE, we add a SELECT
operation as follows
• Example (not meaningful):
• FEMALE_EMPS ¬ s SEX=’F’(EMPLOYEE)
• EMPNAMES ¬ p FNAME, LNAME, SSN (FEMALE_EMPS)
• EMP_DEPENDENTS ¬ EMPNAMES x DEPENDENT
• EMP_DEPENDENTS will contain every combination of EMPNAMES and DEPENDENT
• whether or not they are actually related
• Example (meaningful):
• FEMALE_EMPS ¬ s SEX=’F’(EMPLOYEE)
• EMPNAMES ¬ p FNAME, LNAME, SSN (FEMALE_EMPS)
• EMP_DEPENDENTS ¬ EMPNAMES x DEPENDENT
• ACTUAL_DEPS ¬ s SSN=ESSN(EMP_DEPENDENTS)
• RESULT ¬ p FNAME, LNAME, DEPENDENT_NAME (ACTUAL_DEPS)
• RESULT will now contain the name of female employees and their dependents

35
The CARTESIAN PRODUCT (CROSS
PRODUCT) operation.

36
The CARTESIAN PRODUCT (CROSS
PRODUCT) operation.

SSN = ESSN

37
The CARTESIAN PRODUCT (CROSS
PRODUCT) operation.

38
Binary Relational Operations: JOIN
• JOIN Operation (denoted by )
• The sequence of CARTESIAN PRODECT followed by SELECT is used quite commonly to
identify and select related tuples from two relations
• A special operation, called JOIN combines this sequence into a single operation
• This operation is very important for any relational database with more than a single
relation, because it allows us combine related tuples from various relations
• The general form of a join operation on two relations R(A1, A2, . . ., An) and S(B1, B2,
. . ., Bm) is:
R <join condition>S
• where R and S can be any relations that result from general relational algebra
expressions.

39
Time for Class Activity
• This is a group activity, and you need to sit with your group members
to solve the provided worksheets.

40
Example:
• Example: Suppose that we want to retrieve the name of the
manager of each department.
• To get the manager’s name, we need to combine each
DEPARTMENT tuple with the EMPLOYEE tuple whose SSN value
matches the MGRSSN value in the department tuple.
• We do this by using the join operation.

• DEPT_MGR ¬ DEPARTMENT MGRSSN=SSN EMPLOYEE


• MGRSSN=SSN is the join condition
• Combines each department record with the employee who
manages the department
• The join condition can also be specified as DEPARTMENT.MGRSSN=
EMPLOYEE.SSN

43
Result of the JOIN operation

DEPT_MGR ← DEPARTMENT Mgr_ssn=SsnEMPLOYEE.

44
Some properties of JOIN
• Consider the following JOIN operation:
• R(A1, A2, . . ., An) S(B1, B2, . . ., Bm)
R.Ai=S.Bj
• Result is a relation Q with degree n + m attributes:
• Q(A1, A2, . . ., An, B1, B2, . . ., Bm), in that order.
• The resulting relation state has one tuple for each combination of tuples—r from R
and s from S, but only if they satisfy the join condition r[Ai]=s[Bj]
• Hence, if R has nR tuples, and S has nS tuples, then the join result will generally have
less than nR * nS tuples.
• Only related tuples (based on the join condition) will appear in the result

45
Binary Relational Operations: THETA JOIN
• The general case of JOIN operation is called a Theta-join: R S
theta
• The join condition is called theta
• Theta can be any general boolean expression on the attributes of R
and S; for example:
• R.Ai<S.Bj AND (R.Ak=S.Bl OR R.Ap<S.Bq)

46
Binary Relational Operations: EQUIJOIN
• EQUIJOIN Operation
• The most common use of join involves join conditions with equality
comparisons only
• Such a join, where the only comparison operator used is =, is called
an EQUIJOIN.
• In the result of an EQUIJOIN we always have one or more pairs of attributes
(whose names need not be identical) that have identical values in every
tuple.
• The JOIN seen in the previous example was an EQUIJOIN.

47
Binary Relational Operations: NATURAL JOIN
Operation
• NATURAL JOIN Operation
• Another variation of JOIN called NATURAL JOIN — denoted by * — was created to
get rid of the second (superfluous) attribute in an EQUIJOIN condition.
• because one of each pair of attributes with identical values is superfluous
• The standard definition of natural join requires that the two join attributes, or each
pair of corresponding join attributes, have the same name in both relations
• If this is not the case, a renaming operation is applied first.

48
Example - Equijoin
• List the names and comments of all clients who have viewed a
property for rent.
• (PclientNo, fName, lName(Client)) Client.clientNo = Viewing.clientNo (PclientNo,
propertyNo, comment(Viewing))

49
Example - Natural join
• List the names and comments of all clients who have viewed a
property for rent.
(PclientNo, fName, lName(Client))
(PclientNo, propertyNo, comment(Viewing))

50
Complete Set of Relational Operations
• The set of operations including SELECT s, PROJECT p , UNION È,
DIFFERENCE - , RENAME r, and CARTESIAN PRODUCT X is called a
complete set because any other relational algebra expression can be
expressed by a combination of these five operations.
• For example:
• R Ç S = (R È S ) – ((R - S) È (S - R))
•R <join condition>S = s <join condition> (R X S)

51
Division
• R÷S
• Defines a relation over the attributes C that consists of set of
tuples from R that match combination of every tuple in S.

• Expressed using basic operations:


T1 ¬ PC(R)
T2 ¬ PC((S X T1) – R)
T ¬ T1 – T2

52
Relational Algebra Operations

53
Example - Division
• Identify all clients who have viewed all properties with three rooms.

• (PclientNo, propertyNo(Viewing)) ÷ (PpropertyNo(srooms = 3 (PropertyForRent)))

54
Operations of Relational Algebra

55
Operations of Relational Algebra

56
Query Tree Notation
• Query Tree
• An internal data structure to represent a query
• Standard technique for estimating the work involved in executing the query, the
generation of intermediate results, and the optimization of execution
• Nodes stand for operations like selection, projection, join, renaming, division, ….
• Leaf nodes represent base relations
• A tree gives a good visual feel of the complexity of the query and the operations
involved
• Algebraic Query Optimization consists of rewriting the query or modifying the query
tree into an equivalent tree.

57
Example of Query Tree

58
Additional Relational Operations: Aggregate
Functions and Grouping
• A type of request that cannot be expressed in the basic relational algebra is to
specify mathematical aggregate functions on collections of values from the
database.
• Examples of such functions include retrieving the average or total salary of all
employees or the total number of employee tuples.
• These functions are used in simple statistical queries that summarize information
from the database tuples.
• Common functions applied to collections of numeric values include
• SUM, AVERAGE, MAXIMUM, and MINIMUM.
• The COUNT function is used for counting tuples or values.

59
Aggregate Function Operation
• Use of the Aggregate Functional operation ℱ
• ℱMAX Salary (EMPLOYEE) retrieves the maximum salary value from the EMPLOYEE
relation
• ℱMIN Salary (EMPLOYEE) retrieves the minimum Salary value from the EMPLOYEE
relation
• ℱSUM Salary (EMPLOYEE) retrieves the sum of the Salary from the EMPLOYEE relation
• ℱCOUNT SSN, AVERAGE Salary (EMPLOYEE) computes the count (number) of employees and
their average salary
• Note: count just counts the number of rows, without removing duplicates

60
Additional Relational Operations
rR(Dno, No_of_employees, Average_sal) (Dno ℱ COUNT Ssn, AVERAGE Salary (EMPLOYEE))

Dno ℱ COUNT Ssn, AVERAGE Salary (EMPLOYEE)

ℱ COUNT Ssn, AVERAGE Salary (EMPLOYEE)

61
Additional Relational Operations
• The OUTER JOIN Operation
• In NATURAL JOIN and EQUIJOIN, tuples without a matching (or related) tuple are
eliminated from the join result
• Tuples with null in the join attributes are also eliminated
• This amounts to loss of information.
• A set of operations, called OUTER joins, can be used when we want to keep all the
tuples in R, or all those in S, or all those in both relations in the result of the join,
regardless of whether or not they have matching tuples in the other relation.

62
Additional Relational Operations
• The left outer join operation keeps every tuple in the first or left
relation R in R S; if no matching tuple is found in S, then the
attributes of S in the join result are filled or “padded” with null values.
• A similar operation, right outer join, keeps every tuple in the second
or right relation S in the result of R S.
• A third operation, full outer join, denoted by keeps all tuples
in both the left and the right relations when no matching tuples are
found, padding them with null values as needed.

63
Additional Relational Operations
TEMP ¬ (EMPLOYEE Ssn=Mgr_ssn DEPARTMENT)

RESULT ¬ π Fname, Minit, Lname, Dname (TEMP)

64
Examples of Queries in Relational Algebra :
Procedural Form
n Q1: Retrieve the name and address of all employees who work for the
‘Research’ department.
RESEARCH_DEPT ¬ s DNAME=’Research’ (DEPARTMENT)
RESEARCH_EMPS ¬ (RESEARCH_DEPT EMPLOYEE)
DNUMBER= DNOEMPLOYEE

RESULT ¬ p FNAME, LNAME, ADDRESS (RESEARCH_EMPS)

n Q6: Retrieve the names of employees who have no dependents.


ALL_EMPS ¬ p SSN(EMPLOYEE)
EMPS_WITH_DEPS(SSN) ¬ p ESSN(DEPENDENT)
EMPS_WITHOUT_DEPS ¬ (ALL_EMPS - EMPS_WITH_DEPS)
RESULT ¬ p LNAME, FNAME (EMPS_WITHOUT_DEPS * EMPLOYEE)

65
Examples of Queries in Relational Algebra –
Single expressions
As a single expression, these queries become:
n Q1: Retrieve the name and address of all employees who work for the
‘Research’ department.
p Fname, Lname, Address (σ Dname= ‘Research’
(DEPARTMENT Dnumber=Dno(EMPLOYEE))
n Q6: Retrieve the names of employees who have no dependents.
p Lname, Fname((p Ssn (EMPLOYEE) − ρ Ssn (p Essn
(DEPENDENT))) ∗ EMPLOYEE)

66
Relational Calculus

67
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).
• In a calculus expression, there is no order of operations to specify
how to retrieve the query result—a calculus expression specifies only
what information the result should contain.
• This is the main distinguishing feature between relational algebra and
relational calculus.

68
Tuple Relational Calculus
• The tuple relational calculus is based on specifying a number of tuple variables.
• Each tuple variable usually ranges over a particular database relation, meaning
that the variable may take as its value any individual tuple from that relation.
• A simple tuple relational calculus query is of the form
{t | COND(t)}
• where t is a tuple variable and COND (t) is a conditional expression involving t.
• The result of such a query is the set of all tuples t that satisfy COND (t).

69
Tuple Relational Calculus: Example

70
Quick activity

Write an equivalent query in relational algebra and in SQL

71
Logical Operators
• Logical (or Boolean) operators are used to build atoms that evaluate to either
TRUE or FALSE. These, in turn, are grouped into logical expressions which also
have a truth value.

CS 5200 Fall 2023 by Lee 73


Bound vs Free Tuple Variables
• A tuple variable t is said to be bound, if it is quantified, i.e., it
appears in either a (∃t) or a (∀t) clause, otherwise, it is said to
be free.

74
Example
• books (isbn, title, price, category, page count, pid)
• publishers (pid, pname, address, phone, url)

• Retrieve names and phones of the publishers that publish textbooks

75
The Domain Relational Calculus
• Another variation of relational calculus called the domain relational calculus, or simply, domain
calculus is equivalent to tuple calculus and to relational algebra.
• The language called QBE (Query-By-Example) that is related to domain calculus was developed
almost concurrently to SQL at IBM Research, Yorktown Heights, New York.
• Domain calculus was thought of as a way to explain what QBE does.
• Domain calculus differs from tuple calculus in the type of variables used in formulas:
• Rather than having variables range over tuples, the variables range over single values from
domains of attributes.
• To form a relation of degree n for a query result, we must have n of these domain variables— one
for each attribute.

76
The Domain Relational Calculus
• An expression of the domain calculus is of the form
{ x1, x2, . . ., xn | COND(x1, x2, . . ., xn, xn+1, xn+2, . . ., xn+m)}
• where x1, x2, . . ., xn, xn+1, xn+2, . . ., xn+m are domain variables that range over
domains (of attributes)
• and COND is a condition or formula of the domain relational calculus.

77
Example Query Using Domain Calculus
Retrieve the birthdate and address of the employee whose name is ‘John B. Smith’.
• Query :
{uv | ($ q) ($ r) ($ s) ($ t) ($ w) ($ x) ($ y) ($ z)
(EMPLOYEE(qrstuvwxyz) and q=’John’ and r=’B’ and s=’Smith’)}
• Abbreviated notation EMPLOYEE(qrstuvwxyz) uses the
variables without the separating commas: EMPLOYEE(q,r,s,t,u,v,w,x,y,z)
• 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.

78
Summary
• Relational Algebra
• Unary Relational Operations
• Relational Algebra Operations From Set Theory
• Binary Relational Operations
• Additional Relational Operations
• Examples of Queries in Relational Algebra
• Relational Calculus
• Tuple Relational Calculus
• Domain Relational Calculus

79
Exercises for Your Practice (No Solutions)
• Specify and execute the following queries in relational algebra using the
RA interpreter on the COMPANY database schema
1. List the names of all employees in department 5 who work more than
10 hours per week on the ProductX project
2. List the names of all employees who have a dependent with the same
first name as themselves
3. List the names of employees who are directly supervised by Fanklin
Wong
4. List the names of employees who work on every project
5. List the names of employees who work on at least one project located
in Houston but whose department has no locations in Houston
6. List the names of department managers who have no dependents.
80
Homework
• Resources: The slides contain content from all three textbooks
• Exercise Lab 4: Connecting MySQL
• Please, complete the following and then submit the captured file to Canvas.
• Capture a screenshot of mysqls that shows success of the following commands
• Connect to MySQL on GCP
• Create a user
• Create a database
• Show databases
• Submit the screen shots into Canvas.
• Homework 4:
• Relational Algebra
• SQL Workshop
• Submit WS4-3.sql

81
Related videos
• WATCH: Relational Algebra
• https://northeastern.hosted.panopto.com/Panopto/Pages/Viewer.aspx?id=87
af9a63-bf7a-4bc9-8fb8-abe60140d284&start=0
• https://northeastern.hosted.panopto.com/Panopto/Pages/Viewer.aspx?id=1d
0c33b6-670f-4411-864b-abe701817843&start=0
• WATCH: Relational Calculus
• https://northeastern.hosted.panopto.com/Panopto/Pages/Viewer.aspx?id=2f
99c78c-c697-4543-ad26-ad5c0164fe08&start=0

82

You might also like