Relational Operation
Presented by:-
Nikhat , Abhishek, Shubham, Sonu & Riya
WHAT IS RELATIONAL
ALGEBRA?
• It is a Procedural Query Language.
• It is just a Mathematical Function that is used to retrieve queries by
describing a sequence of operation on their tables or even databases
involved.
FUNDAMENTAL OPERATION IN RELATIONAL
ALGEBRA:-
• SELECTION.
• PROJECTION.
• SET DIFFERENCE.
• CARTESIAN PRODUCT.
• UNION.
• RENAME.
SELECTION OPERATION
EID ENAME
1 A
2 B
3 C
• It is denoted by ‘σ’ Sigma symbol.
• SYNTAX:- σ(SELECT CONDITION)R.
• In Relational Algebra to retrieve data from a tuple selection
operation is used.
IMPORTANT POINTS:-
• Selection Operation can use comparisons using ‘=‘, ’<‘, ’<=‘, ‘>’,
‘>=‘, ‘!=‘ operators.
• We can Merge two Select Condition with the help of
“CONNECTIVES”.
• The Connectives used are AND(∧),OR(∨),and NOT(¬).
• Select Operation is “COMMUTATIVE”.
EID CITY ENAME SAL
1 DELHI A 1K
2 MUMBAI B 2K
3 DELHI C 3K
4 CHENNAI D 4K
When we write:-
σ CITY=DELHI(EMPLOYEE)
RESULT:-
1 DELHI A 1K
3 DELHI C 3K
If we will write:
σ
sal>2k[σCITY=DELHI]EMPLOYEE]
RESULT:-
3
DELHI
C 3K
If we will write like this:
[ σ sal>2kEMPLOYEE]
RESULT:-
3 DELHI C 3K
4 CHENN
AI
D 4K
Then we will write:-
σ CITY=DELHI[σSal>2K
(EMPLOYEE)]
RESULT:-
3
DEL
HI
C 3K
Projection
Operation
Projection (∏) Pi
• Projection is used to project required column data from a
relation.
• Projection is kind portioning which is vertical basically we
dividing the table vertically
By Default projection removes duplicate data.
𝜋(attribute 𝑙𝑖𝑠𝑡)(Relation)
Emp
X Y Z
1 a c
1 b c
2 a c
2 b c
𝜋(XY)(Emp)
X Y
1 a
1 b
2 a
2 b
𝜋(Z)(Emp)
Z
c
SELECT ≅ 𝑷𝒓𝒐𝒋𝒆𝒄𝒕𝒊𝒐𝒏
SELECT DISTINCT ≅ 𝑷𝒓𝒐𝒋𝒆𝒄𝒕𝒊𝒐𝒏
SET
OPERATION
What are the SET operation possible on the Relational
Algebra Operation?
Till now what ever operation we have seen they are unary now we are going to see binary mean we have to take to two
Relations and operate on it
Now when ever we have to take two operation to operate on it (Union, Interaction, Set Difference) they should we
compatible for this Operation
1.Union (U)
2.Set Difference (-)
Union Operation (U)
It performs binary union between two given relations and is defined as.
R U S
Where R and S are either database relations or relation result set (temporary relation).
For a union operation to be valid, the following conditions must hold −
• R and S must have the same number of attributes.
• Attribute domains must be compatible.
• Duplicate tuples are automatically eliminated.
Ex: of Union Operation
∏ author (Books) ∪ ∏ author (Articles)
Output − Projects the names of the authors who have either written a book or
an article or both.
Set Difference (-)
The result of set difference operation is tuples, which are present in one relation
but are not in the second relation.
(R-S)
What ever tuples are present in R and not present in S they will be present in Result
Finds all the tuples that are present in r but not
in s.
∏ author (Books) − ∏ author (Articles)
Output − Provides the name of authors who have written books but not
articles.
Union Operation (∪)
It performs binary union between two given relations and is defined as −
r ∪ s = { t | t ∈ r or t ∈ s}
Notation − r U s
Where r and s are either database relations or relation result set (temporary
relation).
For a union operation to be valid, the following conditions must hold−
 r, and s must have the same number of attributes.
 Attribute domains must be compatible.
 Duplicate tuples are automatically eliminated.
S1 S2
S1∪S2
sno descrip price
1 pen 15
2 pencil 4
3 rubber 5
sno descrip price
8 Scissor 10
11 Scale 5
sno descrip price
1 pen 15
2 pencil 4
3 rubber 5
8 Scissor 10
11 Scale 5
Q. Find the names of all bank customer who have either an account or loan or both.
account(ano,bname,bal)
branch(bname,bcity,assets)
customer(cname,cstreet,ccity)
loan(lno,bname,amt)
 depositor(cname,ano)
 borrower(cname,cno)
cname (borrower) =>{xyz,qwerty,abc,mohan}
cname (depositor) =>{mnop,asd,mohan}
cname (borrower) ∪ cname (depositor)
=> {xyz,qwerty,abc,mohan, mnop,asd}
Cartesian Product
• Each tuple in R1 with each tuple in R2
• Notation: R1  R2
• Example:
– Employee  Dependents
Cartesian Product Example
Employee
Name SSN
John 999999999
Tony 777777777
Dependents
EmployeeSSN Dname
999999999 Emily
777777777 Joe
Employee x Dependents
Name SSN EmployeeSSN Dname
John 999999999 999999999 Emily
John 999999999 777777777 Joe
Tony 777777777 999999999 Emily
Tony 777777777 777777777 Joe
RENAME
OPERATION
The results of relational algebra are also relations but without any name.
Rename is a unary operation which allows us to rename the output
relation.
The rename operation is denoted using small Greek letter rho (ρ).
Rename operator represented as:
ρ x (E)
To rename STUDENT relation to STUDENT1, we can use
rename operator like:
ρ ( STUDENT)
STUDENT1
If you want to create a relation STUDENT_NAMES with
ROLL_NO and NAME from STUDENT, it can be done using
rename operator as:
ρ(STUDENT_NAMES, ∏(ROLL_NO, NAME)(STUDENT))

Relational operation final

  • 1.
    Relational Operation Presented by:- Nikhat, Abhishek, Shubham, Sonu & Riya
  • 2.
  • 3.
    • It isa Procedural Query Language. • It is just a Mathematical Function that is used to retrieve queries by describing a sequence of operation on their tables or even databases involved.
  • 4.
    FUNDAMENTAL OPERATION INRELATIONAL ALGEBRA:- • SELECTION. • PROJECTION. • SET DIFFERENCE. • CARTESIAN PRODUCT. • UNION. • RENAME.
  • 5.
  • 6.
    • It isdenoted by ‘σ’ Sigma symbol. • SYNTAX:- σ(SELECT CONDITION)R. • In Relational Algebra to retrieve data from a tuple selection operation is used.
  • 7.
    IMPORTANT POINTS:- • SelectionOperation can use comparisons using ‘=‘, ’<‘, ’<=‘, ‘>’, ‘>=‘, ‘!=‘ operators. • We can Merge two Select Condition with the help of “CONNECTIVES”. • The Connectives used are AND(∧),OR(∨),and NOT(¬). • Select Operation is “COMMUTATIVE”.
  • 8.
    EID CITY ENAMESAL 1 DELHI A 1K 2 MUMBAI B 2K 3 DELHI C 3K 4 CHENNAI D 4K
  • 9.
    When we write:- σCITY=DELHI(EMPLOYEE) RESULT:- 1 DELHI A 1K 3 DELHI C 3K
  • 10.
    If we willwrite: σ sal>2k[σCITY=DELHI]EMPLOYEE] RESULT:- 3 DELHI C 3K
  • 11.
    If we willwrite like this: [ σ sal>2kEMPLOYEE] RESULT:- 3 DELHI C 3K 4 CHENN AI D 4K Then we will write:- σ CITY=DELHI[σSal>2K (EMPLOYEE)] RESULT:- 3 DEL HI C 3K
  • 12.
  • 13.
    Projection (∏) Pi •Projection is used to project required column data from a relation. • Projection is kind portioning which is vertical basically we dividing the table vertically By Default projection removes duplicate data. 𝜋(attribute 𝑙𝑖𝑠𝑡)(Relation)
  • 14.
    Emp X Y Z 1a c 1 b c 2 a c 2 b c 𝜋(XY)(Emp) X Y 1 a 1 b 2 a 2 b 𝜋(Z)(Emp) Z c
  • 15.
    SELECT ≅ 𝑷𝒓𝒐𝒋𝒆𝒄𝒕𝒊𝒐𝒏 SELECTDISTINCT ≅ 𝑷𝒓𝒐𝒋𝒆𝒄𝒕𝒊𝒐𝒏
  • 16.
  • 17.
    What are theSET operation possible on the Relational Algebra Operation?
  • 18.
    Till now whatever operation we have seen they are unary now we are going to see binary mean we have to take to two Relations and operate on it Now when ever we have to take two operation to operate on it (Union, Interaction, Set Difference) they should we compatible for this Operation
  • 19.
  • 20.
    Union Operation (U) Itperforms binary union between two given relations and is defined as. R U S Where R and S are either database relations or relation result set (temporary relation). For a union operation to be valid, the following conditions must hold − • R and S must have the same number of attributes. • Attribute domains must be compatible. • Duplicate tuples are automatically eliminated.
  • 21.
    Ex: of UnionOperation ∏ author (Books) ∪ ∏ author (Articles) Output − Projects the names of the authors who have either written a book or an article or both.
  • 22.
    Set Difference (-) Theresult of set difference operation is tuples, which are present in one relation but are not in the second relation. (R-S) What ever tuples are present in R and not present in S they will be present in Result Finds all the tuples that are present in r but not in s. ∏ author (Books) − ∏ author (Articles) Output − Provides the name of authors who have written books but not articles.
  • 23.
    Union Operation (∪) Itperforms binary union between two given relations and is defined as − r ∪ s = { t | t ∈ r or t ∈ s} Notation − r U s Where r and s are either database relations or relation result set (temporary relation). For a union operation to be valid, the following conditions must hold−  r, and s must have the same number of attributes.  Attribute domains must be compatible.  Duplicate tuples are automatically eliminated.
  • 24.
    S1 S2 S1∪S2 sno descripprice 1 pen 15 2 pencil 4 3 rubber 5 sno descrip price 8 Scissor 10 11 Scale 5 sno descrip price 1 pen 15 2 pencil 4 3 rubber 5 8 Scissor 10 11 Scale 5
  • 25.
    Q. Find thenames of all bank customer who have either an account or loan or both. account(ano,bname,bal) branch(bname,bcity,assets) customer(cname,cstreet,ccity) loan(lno,bname,amt)  depositor(cname,ano)  borrower(cname,cno) cname (borrower) =>{xyz,qwerty,abc,mohan} cname (depositor) =>{mnop,asd,mohan} cname (borrower) ∪ cname (depositor) => {xyz,qwerty,abc,mohan, mnop,asd}
  • 26.
    Cartesian Product • Eachtuple in R1 with each tuple in R2 • Notation: R1  R2 • Example: – Employee  Dependents
  • 27.
    Cartesian Product Example Employee NameSSN John 999999999 Tony 777777777 Dependents EmployeeSSN Dname 999999999 Emily 777777777 Joe Employee x Dependents Name SSN EmployeeSSN Dname John 999999999 999999999 Emily John 999999999 777777777 Joe Tony 777777777 999999999 Emily Tony 777777777 777777777 Joe
  • 28.
  • 29.
    The results ofrelational algebra are also relations but without any name. Rename is a unary operation which allows us to rename the output relation. The rename operation is denoted using small Greek letter rho (ρ). Rename operator represented as: ρ x (E)
  • 30.
    To rename STUDENTrelation to STUDENT1, we can use rename operator like: ρ ( STUDENT) STUDENT1 If you want to create a relation STUDENT_NAMES with ROLL_NO and NAME from STUDENT, it can be done using rename operator as: ρ(STUDENT_NAMES, ∏(ROLL_NO, NAME)(STUDENT))