0% found this document useful (0 votes)
44 views71 pages

COMP5320 2025 Wk2 L1 RelationalAlgebra - Tagged

Lecture 3 of COMP5320 covers the relational model, focusing on relational algebra operations such as restrict, project, union, intersection, difference, Cartesian product, and join. It emphasizes the importance of relational languages for data manipulation and retrieval, highlighting the procedural nature of relational algebra compared to the declarative nature of relational calculus. The lecture also discusses the implementation of these operations in SQL and the concept of union compatibility among tables.

Uploaded by

EGISKYS DAHACKR
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views71 pages

COMP5320 2025 Wk2 L1 RelationalAlgebra - Tagged

Lecture 3 of COMP5320 covers the relational model, focusing on relational algebra operations such as restrict, project, union, intersection, difference, Cartesian product, and join. It emphasizes the importance of relational languages for data manipulation and retrieval, highlighting the procedural nature of relational algebra compared to the declarative nature of relational calculus. The lecture also discusses the implementation of these operations in SQL and the concept of union compatibility among tables.

Uploaded by

EGISKYS DAHACKR
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 71

Lecture 3

Relational
Model(2)
COMP5320: DATABASE SYSTEMS
Va n e s s a B o n t h u y s ( v. b o n t h u y s @ ke n t . a c . u k)
S t e f a n M a rr ( s . m a rr @ ke n t . a c . u k)
Ke m i Ad e m o y e ( k . a d e m o y e @ ke n t . a c . u k)
Acknowledgements: Many thanks to Stefan Marr & Peter Rodgers for lecture notes from previous ears.
Assessment 1: Class Exercises
Started this week
Reminder
Solve assignments in class.
If needed, finish after class.

Next week: worksheets


are marked in-class

2
Today's lecture:
• Relational Languages
• Relational algebra operations:
• Restrict
• Project
• Union
• Intersection
• Difference
• Cartesian product
• Join

3
Why bother with the theory?
Someone asks: “What is the address of Kate?”
sid FirstName LastName Gender Address Phone
S1 Kate Adams F 1 High St …561

S2 John Smith M 2 Station Rd …642

S3 Kate Johns F 5 Church Rd …546


What was the problem
S4 Fred Taylor M 10 Park St …656
with this question?

Natural Language is
Ambiguous!
Need a little more precision
5

5
Looking at SQL

SELECT FirstName, Address FROM Students WHERE FirstName = 'Kate';


Students
Steps: sid FirstName LastName Gender Address Phone
1. Find all the rows with Kate – RESTRICT S1 Kate Adams F 1 High St …561
operation
S2 John Smith M 2 Station Rd …642
2. Only choose the first name and address
column – PROJECT operation S3 Kate Johns F 5 Church Rd …546

S4 Fred Taylor M 10 Park St …656

6
Looking at SQL

SELECT FirstName, Address FROM Students WHERE FirstName = 'Kate';


StudentKate
Steps: sid FirstName LastName Gender Address Phone
1. Find all the rows with Kate – RESTRICT
S1 Kate Adams F 1 High St …561
operation
S3 Kate Johns F 5 Church Rd …546
2. Only choose the first name and address
columns – PROJECT operation
ResultKate
FirstName Address
Kate 1 High St
StudentKate = RESTRICT Student WHERE FirstName = ‘Kate’;
Kate 5 Church Rd
ResultKate = PROJECT StudentKate OVER FirstName, Address;

7
Queries in relational
algebra(1)
• Query languages allows manipulation and retrieval of data from a
database
• Relational model supports simple, powerful queries
• Strong formal foundation based on logic
• Allows for much optimisation
• Very useful for representing execution plans

8
Queries in relational
algebra(2)
• To respond to a user query, several operations may have to be
performed, the example used Restrict and Project – in a few slides

• Relational algebra is a procedural language


• query is evaluated in the order specified

• Complex queries are evaluated by


• Nesting operations to create a relational expression, or
• Applying operations one at a time and creating temporary tables

9
Queries in relational
algebra(3)
• There may be more than one way to process a complex query

• The most efficient one is preferable


• query optimization it to be covered after project week
• SQL is essentially built on relational algebra

10
Relational
Languages
REL ATIONAL ALGEBRA
REL ATIONAL CALCULUS

11
Relational Languages:
• The table model comprises of:
• Structural definitions
• Integrity rules
• Data manipulation
• Two major languages proposed by Codd to deal with
data manipulation
• Relational algebra
• Relational calculus (not covered in this module)

12
Relational Algebra vs.
Relational Calculus
SIMILARITIES DIFFERENCES
Formal, theoretical based on Relational Algebra Relational calculus
mathematical principles, non-user- Is procedural Is declarative
friendly languages
Used as basis for Data Manipulation Specifies how to Specifies what is to be
Languages for relational database achieve results achieved
Used to define operations to
manipulate tables List all staff with a To find details of all
Equivalent in terms of expressive salary greater than staff earning more than
power £10,000. £10,000:
salary > 10000 (Staff) {S | Staff(S)  S.salary > 10000}

13
Relational Algebra (1)
revision
• Is a theoretical language
• Provides a collection of operations used to manipulate tables
• Is implementable
• Basis for SQL query execution
• Operations may be It’s a very basic
• Unary – One table programming
• Binary – Two tables language!

14
Relational Algebra (2)
facts
• Relational algebra operations work on one(unary) or more
tables(binary), to define another table without changing
the original tables
• Both operands and results are tables, so output from one
operation become input to another operation.
• Allows expressions to be nested, just as in arithmetic.
• Operations produce only tables based on elements of the
input tables, this property is called closure

15
Relational Algebra (3) operations 5
+2
• Five basic operations which perform most of the data
retrieval operation:
• Restrict (Unary operator)
• Projection (Unary operator)
• Cartesian product
• Union
• Set Difference
• Another two operations which can be expressed in terms of
the basic operations:
• Join
• Intersection

16
Relational Algebra symbols
Relational algebra operations symbols we use:


The “bowtie” character in Unicode.
◦ Restrict (useful for assessments and notes)

◦ Project 
◦ Union  Join ⋈
◦ Intersection  Equi-Join
◦ Difference – Natural Join
◦ Cartesian product X Outer Join

17
Relational Algebra
THE BASIC REL ATIONAL ALGEBRA OPERATIONS

18
A visual interpretation
summary

Restrict

Connolly, T. and Begg, C. (2014). Database Systems: A Practical Approach to Design, Implementation, and Management, 6th Edition Pearson Education © 2014 19
Example from lecture 1: Student ( sid, name, gender )
Registration ( sid, cid, mark )

Student ( sid, name, gender )


Registration ( sid, cid, mark )
Two tables: Student and Registration in a university student
database Columns
Table Registration

Relationship sid cid mark


Registered on S1 C1 65

Student S1 C2 45
sid name gender S2 C2 80
S1 Kate F S2 C4 60
Rows
(S1, Kate, F) S2 John M S3 C1 50

S3 Kate F S3 C2 75
S4 Fred M S4 C3 70

20
Restrict operation (1)

MaleStudent   (Gender=‘M’) ( Student )

Restrict

Defines a table, T2 (MaleStudent), that contains only those rows


from the Student table, T1, where the column Gender is ‘M’

21
Example – Restrict

MaleStudent   (Gender=‘M’) ( Student )


Student
sid name gender
MaleStudent
Restrict
SID Name Gender
S1 Kate F
S2 John M
S2 John M
S4 Fred M
S3 Kate F

S4 Fred M

S5 Dan O

The table MaleStudent (T2) is formed by selecting all rows from Student table
(T1) where the column Gender is ‘M’ is predicate, i.e. condition

22
Restrict operation (2)
Restrict use the  (sigma) symbol
We call this a Unary operator, as it works on a single table
Defines horizontal subset of a table (row) as per image
Restrict
T2   (condition/predicate) ( T1 )
table T2 is formed by selecting all rows from table T1 that satisfy the predicate, i.e. condition
Alternatively:
T2 = RESTRICT T1 WHERE condition

the results – left, operation on right produce the results on the left

23
Restrict operation (3)

Comparison operators (<cmpOp>) are:

<, >, <=, >=, =, 

<colName> <cmpOp> [<colName>|<const>]


[<colName>|<const>] means either colName or const
--> we can compare to another column or a constant

24
Restrict operation (3)
e.g. Mark >= 40 (students who reached the pass mark)
Passed   (Mark>=40) ( Registration )
Registration
sid cid mark Passed
S1 C1 75 sid cid mark
S1 C2 40 S1 C1 75
S2 C2 80
S1 C2 40
S2 C4 60
S2 C2 80
S2 C5 35
S3 C1 50 S2 C4 60
S3 C2 75 S3 C1 50
S4 C1 39 S3 C2 75
S4 C3 70
S4 C3 70
S4 C5 30

25
Restrict operation (3) SQL
e.g. Mark >= 40
SELECT * FROM Registration WHERE mark >= 40
Registration
sid cid mark Passed
S1 C1 65 sid cid mark
S1 C2 40 S1 C1 65
S2 C2 80
S1 C2 40
S2 C4 60
S2 C2 80
S2 C5 35
S3 C1 50 S2 C4 60
S3 C2 75 S3 C1 50
S4 C1 39 S3 C2 75
S4 C3 70
S4 C3 70
S4 C5 30

26
Restrict operation (4)
Predicate (condition) can be composed using logical operators to connect
two or more predicates:
⋀ (AND) ⋁ (OR) ~ (NOT)

e.g. cid = ‘C2’ ⋀ Mark >= 70 (all taking C2 with a distinction)


C2distinction   (cid = ‘C2’ ^ Mark >= 70) ( Registration )

27
Restrict (Select) operation (4)
e.g. cid = ‘C2’ ⋀ Mark >= 70 (all taking C2 with a distinction)
C2distinction   (cid = ‘C2’ ^ Mark >= 70) ( Registration )

Registration C2distinction
sid cid mark sid cid mark
S1 C1 75 S2 C2 80

S1 C2 45 S3 C2 75

S2 C2 80

S2 C4 60

S3 C1 50

S3 C2 75

S4 C3 70

28
Restrict (Select) operation (4)
SQL
e.g. cid = ‘C2’ ⋀ Mark >= 70 (all taking C2 with a distinction)
SELECT * FROM Registration WHERE cid = ‘C2' AND mark >= 70

Registration C2distinction
sid cid mark sid cid mark
S1 C1 75 S2 C2 80

S1 C2 45 S3 C2 75

S2 C2 80

S2 C4 60

S3 C1 50

S3 C2 75

S4 C3 70

29
Project operation(1)

 Name, Gender ( Student )


Student
sid
sid name
name gender Name Gender
S1
S1 Kate
Kate F Kate F
S2
S2 John
John M John M
S3
S3 Kate
Kate F Fred M
S4
S4 Fred
Fred M Dan O
S5
S5 Dan
Dan O

All duplicate rows have been removed from the table

SQL: SELECT DISTINCT Name, Gender FROM Student;


30
Project operation (2)
Project use the  (pi) symbol
We call this a Unary operator, as it works on a single table
Defines vertical partitioning of a table (column)
T2   col1, col2, ..., coln ( T1 )
table T2 is formed by selecting the specified columns from table T1
All duplicate rows are eliminated, T2 contains same or fewer number of rows
in T1
Alternatively:
T2 = PROJECT T1 OVER col1, col2, …, coln

31
Set operations
Three types of standard set operations
◦ Union 
◦ Intersection 
◦ Difference -

All three set operations


Are binary
Can only be applied to union compatible tables
 Removes all duplicate rows
 Returns rows that appears in both tables
- Returns the rows that are in one and not in the other table
33
Union compatibility(1)
Student PartStudent
sid name gender entry birthdate sid name gender parttime
S1 Kate F 2019 05-01-2000 PS1 John M 25%
S2 John M 2022 31-08-2000 PS2 Anne F 50%
S3 Kate F 2020 28-02-2001
S4 Fred M 2022 14-03-2000

Can tables be made compatible?

34
Union compatibility(1)
Student PartStudent
sid name gender entry birthdate sid name gender parttime
S1 Kate F 2019 05-01-2000 PS1 John M 25%
S2 John M 2022 31-08-2000 PS2 Anne F 50%
S3 Kate F 2020 28-02-2001
 sid, name, gender ( PartStudent )
S4 Fred M 2022 14-03-2000

 sid, name, gender ( Student )

Project operations are often used to provide union compatible tables

35
Union compatibility(1)
Student PartStudent
sid name gender entry birthdate sid name gender parttime
S1 Kate F 2019 05-01-2000 PS1 John M 25%
S2 John M 2022 31-08-2000 PS2 Anne F 50%
S3 Kate F 2020 28-02-2001
 sid, name, gender ( PartStudent )
S4 Fred M 2022 14-03-2000

 sid, name, gender ( Student )

Project operations are often used to provide union compatible tables


i.e. two tables are union compatible if they have the same number of columns and each pair of
the corresponding columns have the same domain

36
Union compatibility(1)
Student PartStudent
sid name gender entry birthdate sid name gender parttime
S1 Kate F 2019 05-01-2000 PS1 John M 25%
S2 John M 2022 31-08-2000 PS2 Anne F 50%
S3 Kate F 2020 28-02-2001
 sid, name, gender ( PartStudent )
S4 Fred M 2022 14-03-2000

 sid, name, gender ( Student )

i.e. two tables are union compatible if they have the same number of columns and each pair of
the corresponding columns have the same domain

37
Union(1)
Union 
Union combines two tables
e.g. T  R  S
◦ Table T is formed by combining all rows of R, or S, or both R and S
◦ R and S are union compatible
◦ All duplicate rows are eliminated so that the result table T is valid
Alternatively,
T = R UNION S
What could union be useful for?

38
Union (1)
Student PartStudent
sid name gender entry birthdate sid name gender parttime
S1 Kate F 2019 05-01-2000 PS1 John M 25%
S2 John M 2022 31-08-2000 PS2 Anne F 50%
S3 Kate F 2020 28-02-2001
 sid, name, gender ( PartStudent )
S4 Fred M 2022 14-03-2000
AllStudent
 sid, name, gender ( Student ) sid name gender
S1 Kate F
AllStudent   sid, name, gender ( Student )   sid, name, gender ( PartStudent ) S2 John M
S3 Kate F
The table AllStudent is formed by adding rows from tables Student and
S4 Fred M
PartStudent once they are union compatible with the same number of
columns and each pair of the corresponding columns have the same domain PS1 John M
PS2 Anne F

39
Intersection operation(1)

Intersection 
e.g. T  R  S
table T contains all rows which are in both tables R and S
R and S must be union compatible
All duplicate rows are eliminated so that the result table T is valid

Alternatively,
T = R INTERSECT S

40
Intersection operation(2)
Student PartStudent
sid name gender entry birthdate sid name gender parttime
S1 Kate F 2019 05-01-2000 PS1 John M 25%
S2 John M 2022 31-08-2000 PS2 Anne F 50%
S3 Kate F 2020 28-02-2001
S4 Fred M 2022 14-03-2000

( Name(Student) )  ( Name(PartStudent) )

OR
( PROJECT Student OVER Name ) INTERSECT ( PROJECT PartStudent OVER Name )

41
Intersection operation(3)
Student PartStudent
sid name gender entry birthdate sid name gender parttime
S1 Kate F 2019 05-01-2000 PS1 John M 25%
S2 John M 2022 31-08-2000 PS2 Anne F 50%
S3 Kate F 2020 28-02-2001
S4 Fred M 2022 14-03-2000
CommonName
name
CommonName  Student  PartStudent
John
( Name(Student) )  ( Name(PartStudent) )

i.e. two tables are union compatible if they have the same number of columns and each pair of
the corresponding columns have the same domain

42
Difference operation(1)
Difference –
e.g. T  R – S
◦ table T contains all rows which are in table R but not in S
◦ table 1(R) and table 2(S) must be union compatible
◦ All duplicate rows are eliminated so that the result table 3 (T) is
valid
Alternatively,
T = R DIFFERENCE S

43
Difference operation(2)
Student PartStudent
sid name gender entry birthdate sid name gender parttime
S1 Kate F 2019 05-01-2000 PS1 John M 25%
S2 John M 2022 31-08-2000 PS2 Anne F 50%
S3 Kate F 2020 28-02-2001
S4 Fred M 2022 14-03-2000

( Name(Student) ) – ( Name(PartStudent) )

OR
( PROJECT Student OVER Name ) DIFFERENCE ( PROJECT PartStudent OVER Name )

44
Difference operation(3)
Student PartStudent
sid name gender entry birthdate sid name gender parttime
S1 Kate F 2019 05-01-2000 PS1 John M 25%
S2 John M 2022 31-08-2000 PS2 Anne F 50%
S3 Kate F 2020 28-02-2001
S4 Fred M 2022 14-03-2000 DiffName
name
Kate
DiffName  Student – PartStudent
Fred
( Name(Student) ) – ( Name(PartStudent) )

i.e. two tables are union compatible if they have the same number of columns and each pair of
the corresponding columns have the same domain

45
Cartesian product(1)
CARTESIAN PRODUCT X
Multiplies two tables
Defines a table that is the concatenation of every row of
table P with every row with table Q
e.g.
PQ  P X Q
Table PQ contains all rows which are the concatenation of
every row of P with every row of Q

46
Cartesian product(2)
Columns with the same name in P and Q must be
prefixed with the table name to maintain the
uniqueness of column names within PQ

table No. of rows No. of columns

P S (2) M (1)
Q T (3) N (1)
PQ S * T (= 6) M + N (= 2)

47
Cartesian product
operation(1)
Example task:
◦ List students’ ID and name together with their course IDs and marks.

Possible solution in 3 steps:


1) Cartesian product of Student and Registration
2) Select those rows where
Student.SID =
Registration.SID
3) Project the columns as specified

48
Cartesian product
operation(2)
TASK: List students’ ID and name together with their course IDs and marks.

Student ( sid, name, gender )


Registration ( sid, cid, mark )
Registration
sid cid mark
S1 C1 65

Student S1 C2 45
sid name gender S2 C2 80
S1 Kate F S2 C4 60

S2 John M S3 C1 50
S3 Kate F S3 C2 75
S4 Fred M S4 C3 70

49
Cartesian product
operation(3)
TASK: List students’ ID and name together with their course IDs and marks.
STEP 1: A  Student X Registration
Cartesian
product
A ( S.SID, Name, Gender, R.SID, CID, Mark )
Registration
sid cid mark
S1 C1 65

Student S1 C2 45
sid name gender S2 C2 80
S1 Kate F S2 C4 60

S2 John M S3 C1 50
S3 Kate F S3 C2 75
S4 Fred M S4 C3 70

50
Cartesian product
operation(4)
TASK: List students’ ID and name together with their course IDs and marks.
STEP 1: A  Student X Registration
Cartesian
product
A ( S.SID, Name, Gender, R.SID, CID, Mark )
A S.SID Name Gender R.SID CID Mark
S1 Kate F S1 C1 65
S1 Kate F S1 C2 45
S1 Kate F S2 C2 80
S1 Kate F S2 C4 60
S1 Kate F S3 C1 50 S – Student
S1 Kate F S3 C2 75
R – Registration
S1 Kate F S4 C3 70
S2 John M S1 C1 65
… … … … … …

51
51
Cartesian product
operation(4)
TASK: List students’ ID and name together with their course IDs and marks.
STEP 2: B   (Student.SID=Registration.SID) ( A )
Select
B ( S.SID, Name, Gender, R.SID, CID, Mark )

B S.SID Name Gender R.SID CID Mark


S1 Kate F S1 C1 65
S1 Kate F S1 C2 45
S2 John M S2 C2 80
S2 John M S2 C4 60
S3 Kate F S3 C1 50
S3 Kate F S3 C2 75
S4 Fred M S4 C3 70

52
52
Cartesian product
operation(5)
TASK: List students’ ID and name together with their course IDs and marks.
STEP 3: Project the columns as specified
Project C   SID, Name, CID, Mark ( B )

C ( SID, Name, CID, Mark )


C SID Name CID Mark
S1 Kate C1 65
S1 Kate C2 45
S2 John C2 80
S2 John C4 60
S3 Kate C1 50 All duplicate rows have been removed from
S3 Kate C2 75 the table columns we are interested in
S4 Fred C3 70

53
53
Cartesian product and Join

Cartesian product and Restrict can be


reduced to a single operation called a Join

Join is a derivative of Cartesian product

54
Joins

We will be looking at:


• Equi-Join
• Natural join
• Outer Join
• Left Outer Join
• Right Outer Join
• Full Outer Join

56
Join operation(1)
Join condition symbol to use
Combines two tables to form a new one
e.g. TU  T p U
◦ Is a derivative of Cartesian product where all elements
satisfy the condition p
◦ Very important/useful relational operation
◦ The columns involved in a join condition p must have the
same domain
Alternatively,
TU = T JOIN U ON condition

57
Join operation(2)
JOIN operation can be written in terms of Restrict and Cartesian product
operations,
i.e.
T1 p T2 =  p ( T1 X T2 )

The result of a join may be empty if no row satisfies the condition

58
Equi-join operation(1)
Condition of Equi-Join contains only equality comparisons
e.g. Student Registration
S.SID=R.SID

Registration
sid cid mark
S1 C1 65

Student S1 C2 45
sid name gender S2 C2 80
S1 Kate F S2 C4 60

S2 John M S3 C1 50
S3 Kate F S3 C2 75
S4 Fred M S4 C3 70

59
Equi-join operation(2)
Condition of Equi-Join contains only equality comparisons
e.g. Student Registration
S.SID=R.SID

S.SID Name Gender R.SID CID Mark


S1 Kate F S1 C1 65 S – Student
S1 Kate F S1 C2 45
R – Registration
S2 John M S2 C2 80
S2 John M S2 C4 60
S3 Kate F S3 C1 50
S3 Kate F S3 C2 75 Note the redundant SID column
S4 Fred M S4 C3 70 60

60
Natural join operation (1)
Natural Join
e.g. TU  T U

◦ TU is an Equi-Join of the two tables T and U over a set of common


columns Z
◦ The common duplicate columns are removed in the resulting table
TU (implicit projection)
Table No. of rows No. of columns
T S M
U T N
Note: K is the number
TU Min(S, T) M+N-K
of common columns Z

61
Natural join operation (2)
e.g. Student Registration

OR Student NATURAL JOIN Registration

Registration
sid cid mark
S1 C1 65

Student S1 C2 45
sid name gender S2 C2 80
S1 Kate F S2 C4 60

S2 John M S3 C1 50

S3 Kate F S3 C2 75

S4 Fred M S4 C3 70

62
Natural join operation (2)
e.g. Student Registration
Only one SID

OR Student NATURAL JOIN Registration SID Name Gender CID Mark


S1 Kate F C1 65
Registration
S1 Kate F C2 45
sid cid mark S2 John M C2 80
S1 C1 65 S2 John M C4 60
S1 C2 45 S3 Kate F C1 50
Student
sid name gender S2 C2 80 S3 Kate F C2 75
S4 Fred M C3 70
S1 Kate F S2 C4 60

S2 John M S3 C1 50

S3 Kate F S3 C2 75

S4 Fred M S4 C3 70

63
Outer Join operation(1)
To display rows in the result that do not have matching values in the join
column, use Outer join
Problem with Natural Join
• Rows not included when
• join columns are null
• or do not have matching rows in another table
• This can cause loss of information
Outer Join
Avoids information loss
Includes unmatched rows in result table

65
Outer Join operation(2)
Types of Outer Join
◦ Left Outer Join
◦ Includes all rows from R1, even the unmatched ones
◦ Missing values of rows from R2 are set to null
◦ Right Outer Join
◦ Includes all rows from R2, even the unmatched ones
◦ Missing values of rows from R1 are set to null
◦ Full Outer Join
◦ Includes all rows from R1 and R2, even the unmatched ones
◦ Missing values are set to null
66
Outer Join operation(3)
List all students including those who do not have a tutor yet
Foreign Primary
key key
Student Staff
StdID Name Tutor StaffNo Name
1234 Bloggs S1 S1 Thompson
Primary
key 5678 Smith S3 S2 Blair
9012 O’Neill S1 S3 Short
7456 Simpson S4 S4 Straw
7890 Jones Null

The column tutor in Student table is a foreign key referring


to the primary key staffNo in Staff table

67
Outer Join operation(4)
List all students including those
who do not have a tutor yet

e.g. Left Outer Join Student and Staff


StudentTutor  Student Staff

StudentTutor ( StdID, Student.Name, Tutor, Staff.Name)

StudentTutor
StdID Student.Name Tutor Staff.Name
1234 Bloggs S1 Thompson
5678 Smith S3 Short
9012 O’Neill S1 Thompson
7456 Simpson S4 Straw
7890 Jones Null Null

68
Queries in relational algebra
• To respond to a user query, several operations may have to be
performed
• Relational algebra is a procedural language
• query is evaluated in the order specified
• Complex queries are evaluated by
• Nesting operations to create a relational expression, or
• Applying operations one at a time and creating temporary
relations
• There may be more than one way to process a complex query
• The most efficient one is preferable
• query optimization is to be covered later in the module
69
Wrap up
REMEMBER THE HOMEWORK TASKS!

70
Join at vevox.app

ID:
109-856-825

https://kentuni.display.vevox.com#/present/698147/6G2GAFFWXQMM3JBGLPLD

71
Summary
•Relational model is a logical, formal data model concerned with data
structure, data integrity and data manipulation based on math
•A table is physically represented as a table, each row represents a
group of related data values.
•Two important integrity constraints are
◦ Entity integrity
◦ Referential integrity
•Relational Algebra
◦ foundation for data manipulation and therefore SQL

72
Summary – symbols we use
•Relational algebra operations:
◦ Restrict (Select) 
◦ Project 
◦ Union 
◦ Intersection 
◦ Difference –
◦ Cartesian product X
◦ Equi-Join; Natural Join; Outer Join ⋈

73
References
•Connolly, T. and Begg, C. (2014). Database Systems:
A Practical Approach to Design, Implementation,
and Management, 6th Edition. Pearson.
•Chapter 5

74
References
05-01-relational-algebra-1.mp4:
https://youtu.be/tii7xcFilOA?si=WfEt5UD70ogqIwRr
05-02-relational-algebra-2.mp4:
https://youtu.be/GkBf2dZAES0?si=trVZpKfF85OHI47k

75

You might also like