RELATION ALGEBRA
• Relation Algebra is a procedural query language
• It gives a step by step process to obtain the result of the query .
• Relational algebra mainly , provides theoretical foundation for relational database and SQL
• It uses operator to perform queries.
Types of relational Operation
RELATIONLA OPERATION
SELECT PROJECT UNION SET RENAME SET CARTESION
OPERATION OPERATION OPERATION INTERSECTIO OPERATION DIFFRENCE PRODUCT
N
1. SELECT OPERATION (σ): The Select operation is used to select a subset of the tuples from a
relation that satisfies a select condition.
• Sigma (σ) is used to denote select operation
• The select operator is univory such that it is applied to a single relation
The general form of select operation is
σ <select condition> (R)
Where σ is used for selection prediction
R is used for relation
Select condition is the relational operators like =,≠, ≤,<, ≥
Example
Name Roll No address
Aman 02 Dehradun
Raman 04 Rishikesh
Arun 08 Delhi
Ankit 13 Bombay
Query:1 - Give all information of student having roll no. is 04
Solution:- σ roll no = 04 (Student)
Query 2 :- Find all the information os student having name is arun and address isdelhi
Solution:- σ name “Arun” and Address= “Delhi”
Or
σ (name + Arun) V (Address=”Delhi”) (Student)
2. Project Operation (π) = project operation selects certain columns from the table and discard
the other columns.
• This operation shows the list of those attributes that we wish to appear in the result.
• Rest of the attributes are Eliminated from the table
The general format for project operation is
Π <Attribute List > (R)
Where the π is the symbol used to represent the project operation and attribute list is the list of
attributes from the attributes of relation R
Example:-
Name Roll No address
Aman 02 Dehradun
Raman 04 Rishikesh
Arun 08 Delhi
Ankit 13 Bombay
Query 01: Find the student name in the student table
Solution: π name (Student)
Query 2= Find the student name and address
Solution”- π name, address (Student)
3. UNION OPERATION (U) :- It perform binary union between two given relations and is defined
as
RUS
Where R and S are either database relation or relation result set (temporary relation)
Union operation to be valid, the following condition must hold
• R and S must have the same number of attributes
• Attribute domains must be compatible
• Duplicate tuple are automatically Eliminates
Example:- π name (Student 1) U π name (Student 2 )
4. Set Intersection (∩):- it performs binary intersection between two given relation and defined
as :-
R∩S
where R and S are either database relations or relation result set
Example
π name (Student 1) ∩ π name (Student 2 )
5. Set Difference (-) The Result of the set difference operation is tuples ,which are present in
one relation but are not in the second relation.
R-S
Notation is find all the tuples that are present in R but not in S
Example :-
π name (Student 1) - π name (Student 2 )
6. Cartesian Product (X): combines information of two different relation into one
RXS
Where R and S are relation and
Their output will be defined as
RXS = {q ∈ I q ∈R and t ∈S}
Example :-
σ name= ‘kamal’ (Student1 X Student 2 )
Rename Operation (ρ):- Rename operation is used to rename the output of a relation rename
operation is denoted with small Greek letter rho(ρ)
ρ x (E)
Where the result of expression E is saved with name of X
Example: - Query to rename the table student to employee and its attributes name, address,
phone number.
ρ employee (name, address, phone no.) (Student)