6ms1102 Ch6 Relational Algebra
6ms1102 Ch6 Relational Algebra
CHAPTER 6
RELATIONAL ALGEBRA
By: Mr.Mumbere Samuel – FICT.
◻ Relational algebra and calculus are the theoretical concepts used on relational
model.
◻ RDBMS is a practical implementation of relational model.
◻ SQL is a practical implementation of relational algebra and calculus.
◻ Every database management system must define a query language to allow users to
access the data stored in the database. Relational Algebra is a procedural query
language used to query the database tables to access data in different ways
◻ In relational algebra, input is a relation(table from which data has to be accessed) and
output is also a relation(a temporary table holding the data asked for by the user).
Figure: 4.1
3. Union
4. Set Different
5. Cartesian product
6. Rename
Binary Operators
Unary Operators
Union ∪
Selection σ
Intersection ∩
Projection π
Difference —
Cartesian product ×
Natural Join ⋈
Logic Symbols Inner Join Using ⋈ a,b
Logical OR
Left Outer Join =⋈
∨
Right Outer Join ⋈=
Logical NOT ¬ Full Outer Join =⋈=
© ISBAT UNIVERSITY – 2020. 12-Dec-22
Select Operation (σ)
Syntax: σp(r)
You can also use, and, or etc operators, to specify two conditions,
for example,
σage > 17 and gender = 'Male' (Student)
© ISBAT UNIVERSITY – 2020. 12-Dec-22
Project Operation (∏)
attributes of a relation
◻ Ex. If you want to see only the names all of the students in
the Student table, then you can use Project Operation
◻ It will only project or show the columns or attributes asked for,
and will also remove duplicate data from the columns
Syntax: ∏A1, A2...(r)
where A1, A2 etc are attribute names(column names).
For example,
∏Name, Age(Student)
Above statement will show us only the Name and Age columns for all the rows of data in Student table
table_name1 ∪ table_name2
Student_Name
------------
Output:
Aditya
Steve
Paul
Lucy
© ISBAT UNIVERSITY – 2020. 12-Dec-22
Set Difference (-)
table_name1 - table_name2
R1 X R2
ρ(new_relation_name, old_relation_name)