Relational Algebra is a procedural query language, it is used to provide a single table / relation as output of performing operations on more than one relations. Some of the basic relations will be discussed here.
In our course of learning, we will use three relations (table) −
On this relations, we will perform some operation to make new relation based on operations performed.
Selection operation (σ) − The selection operator denoted by sigma σ is used to select the tuples of a relation based on some condition. Only those tuples that fall under certain conditions are selected.
Select the student with course id 1. σ(course_id = 1)(student)
Projection operation (∏) The projection operator denoted by ∏ is used to select columns from a specific reaction. Only specific columns are selected.
∏(column1 , column2 , … , columnn)(relation_name)
Let’s select all students's name and no who are in hostel. ∏( st. No. , name)(hostel)
The row are always distinct in projection i.e. if their is any other student whose name is panjak the other one is removed.
Cross Product(X) - Cross product is denoted using the X symbol and is used to find the value of join of two variables. In cross product each tuple of relation1 is crossed with each tuple of relation2. Which makes the output relation of the order nXm, where n is the number of tuples in relation1 and m is the number of tuples in relation2.
relation1 X relation2
Let’s find cross product of course and hostel table.
student X course
Union (U) - The union of two relations relation1 and relation2 will gives the tuples that are either in relation1 or in relation2 but tuples that are in both relation1 and relation2 are considered only once.
Also both relations should be of the same domain for finding there union.
relation1 U relation2
Let’s find the union of student and hostel
student U hostel
Minus (-) operator - operator is denoted by - symbol. Relation1 - relation2 will result into a relation in which the tuple in relation1 and not in relation2 are present. For calculating minus too, the relations must be union compatible.
relation1 - relation2
Let’s find the operation student - hostel
student - hostel
rename(ρ) − the rename operation denoted by the ρ is used to rename the given relation to another name given.
ρ(new_name , old_name)