2. PREPARED BY
Ms.K.Kannika -III-B.Sc - Information Technology
Ms.R.Thirupurasundari -III-B.Sc-Information Technology
UNDER THE GUIDANCE OF
Mrs.P.Anusha M.Sc(IT).,M.Phil.,D.P.T.T.,(Ph.D).,
Assistant professor,
Department of Information Technology,
Bon secours college for women,
Thanjavur.
3. RelAtional algebra :
Relational algebra is a procedural query language. It
gives a step by step process to obtain the result of the
query, it uses operators to perform queries
Relational algebra operation work on one or more relation
to define another relation without changing the original
relations.
4. The fundamental operations of relational algebra are as
follows :
Select
Project
Union
Set difference
Cartesian products
Rename
5. Selection operation:
The select operation selects tuples that satisfy a given predicate
It is denoted sigma (σ)
Notation : σP(r)
Where,
σ is used for selection prediction
r is used for relation
P is used for propositional logic formula which may use
connectors like : AND, OR and NOT. The relation can be use as
relational operators like =, ≠, <=, >=, <, >
6. Example :
Table : Student
Create table student(name varchar(255), age int, mark1 int, mark2
int) ;
Insert into Student values(‘abirami’,’18’,’89’,’67’) ;
Insert into student values(brindha, 18,79,97) ;
Insert into student values(‘seetha’,’19’, ’81’,’84’);
Select *from student ;
Name Age Mark 1 Mark2
Abirami 18 89 67
Brindha 18 79 97
Seetha 19 81 84
8. Project operation :
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
It is denoted by π
Notation : πA1, A2,.........,An (r)
10. Union operation :
Suppose there are two tuples R and S. The Union
operation contains all the tuple that are either in R or S Or
both in R & S
It eliminates the duplicate tuple
It is denoted by U
Notation: R U S
r U s = {t/t ∈ r or t ∈ s}
11. A union operation must hold the following condition :
R and S must have the attribute of the same number
Duplicate tuple are eliminated automatically
12. Example :
Table : student
Table : student1
Create table student1(name varchar (255), age int, mark1 int, mark2);
Insert into student1 values('seetha‘, ’19’, ’85’,’ 84’) ;
Insert into student1 values(‘gobi’, ’20’, ‘95’, ’66’) ;
Insert into student1 values (‘revathi’, ’19’, ’85’, ’77’) ;
select * from student1;
Name Age Mark1 Mark2
Seetha 19 85 84
Gobi 20 95 66
Revathi 19 85 77
13. π name, mark1(student) U πname, mark1(student1) ;
Output :
Name Mark 1
Abirami 89
Brindha 79
Seetha 81
Revathi 85
Gobi 95
14. Set intersection :
Suppose there are two tuples R and S. The set intersection
operation contain all tuples that are in both R & S
It is denoted by intersection ∩
Notation : R ∩ S
16. Set difference:
The result set of difference operation is tuples, which are
present in one relation but are not in the second relation
It is denoted by - minus
Notation : R-S
18. Cartesian products:
The cartesian product is used to combine each row in one
table with each row in the other table it is also known as a
cross product
It is denoted by X
19. Example :
Table : A
Create table A( id_no int, age int, city varchar(255)) ;
Insert into A values (’01’, ‘25‘, ‘chennai’) ;
Insert into A values (’02’, ’24’, ‘Bangalore‘) ;
Select * from A;
Id_no Age City
01 25 Chennai
02 24 Bangalore
20. Table B :
Create table B(exam varchar(20) , mark1 int, mark2 int) ;
Insert into B values ('CIA‘, ’64’, ’56’) ;
Insert into B values(‘model’, ’69’, ’98’) ;
Exam Mark1 Mark2
CIA 64 56
Model 69 98
21. OUTPUT: A X B
Id_no Age City Exam Mark1 Mark2
01 25 Chennai CIA 64 56
01 25 Chennai Model 69 98
02 24 Bangalore CIA 64 56
02 24 Bangalore Model 69 98
22. Rename operation :
The result of relational algebra are also relations but without any
name, the rename operation allows as to rename the output relation.
‘Rename’ operation is denoted with small Greek letter rho ρ
Notation: ρ × (E)
Where the result of the expression E is saved with name of x
We can use the rename operator the rename STUDENT relation to
STUDENT 2
ρ(Student 2,student) ;
23. FORMAL DEFINITION:
A General expression in the relational algebra is constructed out of
smaller sub expressions.Let E1 and E2 be relational algebra
expressions.Then the following are all relational algebra
expressions:
E1 U E2 , E1 ∩ E2
E1 – E2
E1 X E2
(σ) p (E1) Where P is a predicate on attributes in E1.
Π S(E1) Where S is a list consisting of sum of the attributes in E1.
ρ x (E1) Where x is the new name for the result of E1.