Relational AlgebraNewUp
Relational AlgebraNewUp
Relational •
•
Projection
Union
algebra cont.., •
•
Intersection
Rename
It selects tuples that satisfy the given predicate from a relation.
[it is used to select or retrieve data from a relation that satisfies a
particular selection condition.]
Selection
Selection operator
Relation
a particular data
retrieved from a
relation
(=,>,<,=>,=<)
Question 01: select the Department tuples whose department id is
d03.
𝜎 𝑑𝑒𝑝𝑡 𝑖𝑑
′
¿ 𝑑 03 ′
( 𝐷𝑒𝑝𝑎𝑟𝑡𝑚𝑒𝑛𝑡 )
𝜎 ( 𝑑𝑒𝑝𝑡
Question ❑( 𝑑𝑒𝑝𝑡
𝑖𝑑
′
¿′ 𝑑 03′ 𝑎𝑛𝑑 𝑑𝑖𝑛𝑐𝑜𝑚𝑒 > 30000 ) 𝑜𝑟
′
𝑖𝑑 ¿ 𝑑 05 𝑎𝑛𝑑 𝑑𝑖𝑛𝑐𝑜𝑚𝑒 >25000 ) ( 𝐷𝑒𝑝𝑎𝑟𝑡𝑚𝑒𝑛𝑡 )
It projects column(s) that satisfy a given predicate.
Duplicate rows are automatically eliminated, as relation is a set
projection
Projection operator
Relation
a particular data
retrieved from a
relation
(=,>,<,=>,=<)
Question 01: List the following from the department table.
Department id, name, income
𝜋 𝑑𝑒𝑝𝑡 𝑖𝑑
, 𝑑𝑒𝑝𝑡 𝑛𝑎𝑚𝑒 , 𝑑𝑒𝑝𝑡 𝑖𝑛𝑐𝑜𝑚𝑒 ( 𝐷𝑒𝑝𝑎𝑟𝑡𝑚𝑒𝑛𝑡 )
rename
Rename operator
Old Relation name
operation
𝜌 𝑠( 𝑎 1 , 𝑎 2 , 𝑎𝑛) ( 𝑅 )
𝜌 𝑛𝑎𝑚𝑒 / 𝑠𝑡 𝑓𝑛𝑎𝑚𝑒
( 𝑠𝑜𝑓𝑡𝑠𝑡𝑢𝑑𝑒𝑛𝑡 )
Question : select the student first name and last name of all the
student who are studying in the IT division.
Question Question : use the rename operator to store the and answer in a
temp location called stsoft. As a relation.
𝜌 𝑠𝑡𝑠𝑜𝑓𝑡
[𝜎 𝑑𝑒𝑝𝑡𝑛𝑎𝑚𝑒 ¿ 𝐼 𝑇
′ ′ ( 𝑠𝑡𝑢𝑑𝑒𝑛𝑡 ) ]
It performs binary union between two given relations.
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
union hold −
• r, and s must have the same number of attributes.
operation • Attribute domains must be compatible.
• Duplicate tuples are automatically eliminated.
r U s = { t | t ∈ r or t ∈ s}
Question :Predict the names of the students who have either
passed in both IT or in history or both.
operation
𝜋 𝑟𝑒𝑔𝑛𝑜 ( 𝑅 1 ) ∩ 𝜋 𝑟𝑒𝑔𝑛𝑜 ( 𝑅 2 )
Question : Find all the customers whose account is in the bank and
have taken out a loan.
question
select dbo.sum(6,4);
Question 02: write a function to update the status of the
employee table by multiplying a value passed as a parameter?
select dbo.statusupdte(status,4)
from employee;
Question 01: Write a stored procedure to select all from the
employee table.
SQL stored
procedure
Question 02: Write a stored procedure to select all details of the
employee who is having the salary amount 15000 employee table.