3. • 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.
4. FUNDAMENTAL OPERATION IN RELATIONAL
ALGEBRA:-
• SELECTION.
• PROJECTION.
• SET DIFFERENCE.
• CARTESIAN PRODUCT.
• UNION.
• RENAME.
6. • It is denoted by ‘σ’ Sigma symbol.
• SYNTAX:- σ(SELECT CONDITION)R.
• In Relational Algebra to retrieve data from a tuple selection
operation is used.
7. 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”.
8. EID CITY ENAME SAL
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 will write:
σ
sal>2k[σCITY=DELHI]EMPLOYEE]
RESULT:-
3
DELHI
C 3K
11. 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
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
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
17. What are the SET operation possible on the Relational
Algebra Operation?
18. 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
20. 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.
21. 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.
22. 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.
23. 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.
25. 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}
26. Cartesian Product
• Each tuple in R1 with each tuple in R2
• Notation: R1 R2
• Example:
– Employee Dependents
27. 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
29. 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)
30. 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))