SlideShare a Scribd company logo
1 of 24
Download to read offline
Dr. Amiya Ranjan Panda
Assistant Professor [II]
School of Computer Engineering,
Kalinga Institute of Industrial Technology (KIIT),
Deemed to be University,Odisha
Relational Algebra
KALINGA INSTITUTE OF INDUSTRIAL
TECHNOLOGY
School Of Computer
Engineering
4 Credit Lecture Note 11
Chapter Contents
q Query Language
q Relational Algebra
q SELECT Operator (σ)
q PROJECT Operator (π)
q Composition of Relational Operators
q RENAME Operator (ρ)
q Union Compatibility
q UNION Operator (∪)
q DIFFERENCE Operator (-)
q Cartesian Product Operator (×)
q Intersection Operator (∩)
q JOIN Operator (⋉ ⋊ )
q Division Operator (÷)
q Assignment Operator (←)
2
Ø Language in which user requests information from the database are:
ü Procedural language
ü Nonprocedural language
Ø The categories of different languages are:
üSQL
üRelational Algebra
üRelational Calculus
ØTuple Relational Calculus
ØDomain Relational Calculus
3
Query Language
Ø Relational algebra is a procedural language for manipulating relations.
Relational algebra operations manipulate relations. That is, these operations use
one or two existing relations to create a new relation:
Ø Fundamental operators
ü Unary: SELECT, PROJECT, RENAME
ü Binary: UNION, SET DIFFERENCE, CARTESIAN PRODUCT
Ø Secondary operators
ü INTERSECTION, NATURAL JOIN, DIVISION, and ASSIGNMENT
4
Relational Algebra
Ø The relational schemas used for different operations are:
ü Customer(cust_name, cust_street, cust_city)
used to store customer details
ü Branch(branch_name, branch_city, assets)
used to store branch details
üAccount(acc_no, branch_name, balance)
stores the account details
ü Loan(loan_no, branch_name, amount)
stores the loan details
ü Depositor(cust_name, acc_no)
stores the details about the customers’ account
ü Borrower(cust_name, loan_no)
used to store the details about the customers’ loan
5
Relational Algebra…
Ø SELECT operation is used to create a relation from another relation by
selecting only those tuples or rows from the original relation that satisfy a
specified condition. It is denoted by sigma (σ) symbol. The predicate appears as
a subscript to σ.
Ø The argument relation is in parenthesis after the σ. The result is a relation that
has the same attributes as the relation specified in <relation-name>. The general
syntax of select operator is:
σ <selection−condition> (<relation name>)
Ø Query: Find the details of the loans taken from ’Bhubaneswar Main’ branch.
σ branch_name=′ BhubaneswarMain′ (Loan)
ü The operators used in selection predicate may be: =, 6=, <, ≤, >, ≥.
ü Different predicates can be combined into a larger predicate by using the
connectors like: AND(V), OR(W), NOT(¬)
6
SELECT Operator (σ)
7
SELECT Operator (σ)…
Loan
Ø σ branch_name=′ BhubaneswarMain′ (Loan)
Ø σ branch_name=′ BhubaneswarMain′ AND amount >10,000,000 (Loan)
loan_no branch_name amount
L201 Bhubaneswar Main 50,000,000.00
L202 Bhubaneswar Main 5,000,000.00
L203 Mumbai Main 100,000,000.00
L204 Juhu 60,000,000.00
loan_no branch_name amount
L201 L202 Bhubaneswar Main
Bhubaneswar Main
50,000,000.00
5,000,000.00
loan_no branch_name amount
L201 Bhubaneswar Main 50,000,000.00
Ø PROJECT operation can be thought of as eliminating unwanted columns. It
eliminates the duplicate rows. It is denoted by pie (π) symbol. The attributes
needed to be appeared in the resultant relation appear as subscript to π.
Ø The argument relation follows in parenthesis. The general syntax of project
operator is:
π <attribute−list > (<relation name>)
Ø Query: Find the loan numbers and respective loan amounts.
π loan_no,amount (Loan)
8
PROJECT Operator(π)
Loan π loan_no, amount (Loan)
loan_no branch_name amount
L201 Bhubaneswar Main 50,000,000.00
L202 Bhubaneswar Main 5,000,000.00
L203 Mumbai Main 100,000,000.00
L204 Juhu 60,000,000.00
loan_no amount
L201 50,000,000.00
L202 5,000,000.00
L203 100,000,000.00
L204 60,000,000.00
Ø Relational algebra operators can be composed together into a relational algebra
expression to answer the complex queries.
Ø Q: Find the name of the customers who live in Bhubaneswar.
9
Composition of Relational Operators
Customer
π cust _name (σ cust _city =′ Bhubaneswar ′ (Customer))
cust_name cust_street cust_city
Rishi Sarthak Manas
Ramesh Mahesh
India Gate
M. G. Road Shastri Nagar
M. G. Road Juhu
New Delhi Bangalore
Bhubaneswar
Bhubaneswar Mumbai
cust_name
Manas Ramesh
Ø The results of relational algebra expressions do not have a name that can be
used to refer them. It is useful to be able to give them names; the rename
operator is used for this purpose. It is denoted by rho (ρ) symbol.
Ø The general syntax of rename operator is:
ρ X (E)
Ø Assume E is a relational-algebra expression with arity n. The second form of
rename operation is:
ρ X (b1 ,b2 ,...bn ) (E)
Ø π cust _name (σ cust _city =′ Bhubaneswar ′ (Customer)) can be written as:
1. ρCustomer _Bhubaneswar (σ cust _city =′ Bhubaneswar ′ (Customer))
2. π cust_name (Customer_Bhubaneswar)
10
RENAME Operator(ρ)
Ø The different forms of the rename operation for renaming the relation are:
a. ρ S (R)
b. ρ S(b1 ,b2 ,...bn ) (R)
c. ρ (b ,b ,...b ) (R)
Ø For example, the attributes of Customer (cust_name, cust_street, cust_city) can
be renamed as:
ρ (name,street,city) (Customer)
11
RENAME Operator(ρ)…
Ø To perform the set operations such as UNION, DIFFERENCE and
INTERSECTION, the relations need to be union compatible for the result to be
a valid relation.
Ø Two relations R1(a1,a2,... an ) and R2(b1,b2,... bm ) are union compatible iff:
ü n = m, i.e. both relations have same arity
ü dom(ai ) = dom(bi ) for 1 ≤ i ≤ n
12
Union Compatibility
Ø The union operation is used to combine data from two relations. It is denoted by
union(∪) symbol. The union of two relations R1(a1,a2,... an) and R2(b1,b2,... bn)
is a relation R3 (c1,c2,... cn) such that:
dom(ci) = dom(ai) ∪dom(bi), 1 ≤ i ≤ n
Ø R1 ∪R2 is a relation that includes all tuples that are either present in R1 or R2 or
in both without duplicate tuples.
Ø π cust_name (Depositor) ∪ π cust_name (Borrower)
13
UNION Operator (∪)
Ø The difference operation is used to identify the rows that are in one relation and
not in another. It is denoted as (-) symbol. The difference of two relations
R1(a1,a2,... an ) and R2(b1,b2,... bn ) is a relation R3 (c1,c2,... cn ) such that:
dom(ci ) = dom(ai ) - dom(bi ), 1 ≤ i ≤ n
Ø R1 - R2 is a relation that includes all tuples that are in R1, but not in R2.
Ø π cust_name (Depositor) - π cust_name (Borrower)
14
DIFFERENCE Operator(-)
Ø The Cartesian product of two relations R1(a1,a2,... an ) with cardinality i and
R2(b1,b2,... bm ) with cardinality j is a relation R3 with
ü degree k = n + m,
ü cardinality i*j and
ü attributes (a1,a2,... an , b1,b2,... bm ))
Ø R1 × R2 is a relation that includes all the possible combinations of tuples from
R1 and R2. The Cartesian product is used to combine information from any two
relations.
Ø It is not a useful operation by itself; but is used in conjuction with other
operations.
15
Cartesian Product Operator(×)
16
Cartesian Product Operator(×)…
Ø Query: Find out the customer and their loan details taken from Bhubaneswar
Main branch.
A n s : σ b r a n c h _ n a m e = ′ B h u b a n e s w a r M a i n ′ A N D
Borrower.loan_no=Loan.loan_no (Borrower ×Loan)
17
Cartesian Product Operator(×)…
Ø The intersection operation is used to identify the rows that are common to two
relations. It is denoted by (∩) symbol. The intersection of two relations R1
(a1,a2,... an ) and R2 (b1,b2,... bn ) is a relation R3 (c1,c2,... cn ) such that…
dom (ci ) = dom (ai ) ∩ dom (bi ), 1 ≤ i ≤ n
Ø R1 ∩ R2 is a relation that includes all tuples that are present in both R1 and
R2.
Ø The intersection operation can be rewritten by a pair of set difference operations
as R ∩ S = R - (R - S).
π cust_name (Depositor) ∩ π cust_name (Borrower)
18
Intersection Operator(∩)
Ø The join is a binary operation that is used to combine certain selections and a
Cartesian product into one operation. It is denoted by join (⋊ ⋉ ) symbol.
Ø The join operation forms a Cartesian product of its two arguments, performs a
selection forcing equality on those attributes that appear in both relations, and
finally removes the duplicate attributes.
Ø Query: Find the names of customers who have a loan at the bank, along
with the loan number and the loan amount ?
Ans: This query can be solved by using the PROJECT, SELECT and
CARTESIAN PRODUCT operators as:
Π cust _name,Loan.loan_no,amount (σ Borrower .loan_no = Loan.loan_no
(Borrower ×Loan))
Ø This same expression can be simplified by using the JOIN as:
π cust_name, loan_no, amount (Borrower ⋊⋉ Loan))
19
JOIN Operator(⋉)
20
JOIN Operator(⋉)…
Ø The division operation creates a new relation by selecting the rows in one
relation that match every row in another relation. The division operation
requires that we look at an entire relation at once. It is denoted by division (÷)
symbol.
Ø Let A, B, C are three relations and we desire B ÷ C to give A as the result. This
operation is possible iff:
ü The columns of C must be a subset of the columns of B. The columns of A
are all and only those columns of B that are not columns of C
ü A row is placed in A if and only if it is associated with B and with every
row of C
Ø The division operation is the reverse of the Cartesian product operation as: B =
(B × C) ÷ C.
Ø Division operator is suited to queries that include the phrase every or all as part
of the condition.
21
Division Operator (÷)
22
Division Operator (÷)…
Ø It works like assignment in a programming language. In relational algebra, the
assignment operator gives a name to a relation. It is denoted by (←) symbol.
Ø Assignment must always be made to a temporary relation variable. The result of
the right of the ← symbol is assigned to the relation variable on the left of the
← symbol.
Ø With the assignment operator, a query can be written as a sequential program
consisting of:
üa series of assignment,
üfollowed by an expression whose value is displayed as a result of the query
π cust_name,branch_name (Depositor ⋊⋉ Account) ÷ π branch_name (σ
branch_city=′Mumbai′ (Branch)) can be simplified as:
Temp1 ← π cust_name,branch_name (Depositor ⋊⋉ Account)
Temp2 ← π branch_name (σ branch_city=′Mumbai′ (Branch))
Result = Temp1 ÷ Temp2
23
Assignment Operator(←)
24

More Related Content

What's hot

Relational Algebra & Calculus
Relational Algebra & CalculusRelational Algebra & Calculus
Relational Algebra & CalculusAbdullah Khosa
 
Dbms Notes Lecture 9 : Specialization, Generalization and Aggregation
Dbms Notes Lecture 9 : Specialization, Generalization and AggregationDbms Notes Lecture 9 : Specialization, Generalization and Aggregation
Dbms Notes Lecture 9 : Specialization, Generalization and AggregationBIT Durg
 
SQL - Structured query language introduction
SQL - Structured query language introductionSQL - Structured query language introduction
SQL - Structured query language introductionSmriti Jain
 
Data Modeling PPT
Data Modeling PPTData Modeling PPT
Data Modeling PPTTrinath
 
Transaction management DBMS
Transaction  management DBMSTransaction  management DBMS
Transaction management DBMSMegha Patel
 
Relational Database Design
Relational Database DesignRelational Database Design
Relational Database DesignArchit Saxena
 
Degree of relationship set
Degree of relationship setDegree of relationship set
Degree of relationship setMegha Sharma
 
FUNCTION DEPENDENCY AND TYPES & EXAMPLE
FUNCTION DEPENDENCY  AND TYPES & EXAMPLEFUNCTION DEPENDENCY  AND TYPES & EXAMPLE
FUNCTION DEPENDENCY AND TYPES & EXAMPLEVraj Patel
 
Er & eer to relational mapping
Er & eer to relational mappingEr & eer to relational mapping
Er & eer to relational mappingsaurabhshertukde
 
1. Introduction to DBMS
1. Introduction to DBMS1. Introduction to DBMS
1. Introduction to DBMSkoolkampus
 
Architecture of-dbms-and-data-independence
Architecture of-dbms-and-data-independenceArchitecture of-dbms-and-data-independence
Architecture of-dbms-and-data-independenceAnuj Modi
 
Library Management System
Library Management SystemLibrary Management System
Library Management SystemAnit Thapaliya
 
Graphs In Data Structure
Graphs In Data StructureGraphs In Data Structure
Graphs In Data StructureAnuj Modi
 
Transaction states and properties
Transaction states and propertiesTransaction states and properties
Transaction states and propertiesChetan Mahawar
 
Types Of Join In Sql Server - Join With Example In Sql Server
Types Of Join In Sql Server - Join With Example In Sql ServerTypes Of Join In Sql Server - Join With Example In Sql Server
Types Of Join In Sql Server - Join With Example In Sql Serverprogrammings guru
 
Pharmacy management system Requirement Analysis and Elicitation Document
Pharmacy management system Requirement Analysis and Elicitation Document Pharmacy management system Requirement Analysis and Elicitation Document
Pharmacy management system Requirement Analysis and Elicitation Document Habitamu Asimare
 

What's hot (20)

Relational Algebra & Calculus
Relational Algebra & CalculusRelational Algebra & Calculus
Relational Algebra & Calculus
 
Dbms Notes Lecture 9 : Specialization, Generalization and Aggregation
Dbms Notes Lecture 9 : Specialization, Generalization and AggregationDbms Notes Lecture 9 : Specialization, Generalization and Aggregation
Dbms Notes Lecture 9 : Specialization, Generalization and Aggregation
 
SQL - Structured query language introduction
SQL - Structured query language introductionSQL - Structured query language introduction
SQL - Structured query language introduction
 
Data Modeling PPT
Data Modeling PPTData Modeling PPT
Data Modeling PPT
 
Distributed database
Distributed databaseDistributed database
Distributed database
 
Transaction management DBMS
Transaction  management DBMSTransaction  management DBMS
Transaction management DBMS
 
Relational Database Design
Relational Database DesignRelational Database Design
Relational Database Design
 
Degree of relationship set
Degree of relationship setDegree of relationship set
Degree of relationship set
 
FUNCTION DEPENDENCY AND TYPES & EXAMPLE
FUNCTION DEPENDENCY  AND TYPES & EXAMPLEFUNCTION DEPENDENCY  AND TYPES & EXAMPLE
FUNCTION DEPENDENCY AND TYPES & EXAMPLE
 
MYSQL.ppt
MYSQL.pptMYSQL.ppt
MYSQL.ppt
 
SQL Views
SQL ViewsSQL Views
SQL Views
 
Er & eer to relational mapping
Er & eer to relational mappingEr & eer to relational mapping
Er & eer to relational mapping
 
1. Introduction to DBMS
1. Introduction to DBMS1. Introduction to DBMS
1. Introduction to DBMS
 
Architecture of-dbms-and-data-independence
Architecture of-dbms-and-data-independenceArchitecture of-dbms-and-data-independence
Architecture of-dbms-and-data-independence
 
SQL(DDL & DML)
SQL(DDL & DML)SQL(DDL & DML)
SQL(DDL & DML)
 
Library Management System
Library Management SystemLibrary Management System
Library Management System
 
Graphs In Data Structure
Graphs In Data StructureGraphs In Data Structure
Graphs In Data Structure
 
Transaction states and properties
Transaction states and propertiesTransaction states and properties
Transaction states and properties
 
Types Of Join In Sql Server - Join With Example In Sql Server
Types Of Join In Sql Server - Join With Example In Sql ServerTypes Of Join In Sql Server - Join With Example In Sql Server
Types Of Join In Sql Server - Join With Example In Sql Server
 
Pharmacy management system Requirement Analysis and Elicitation Document
Pharmacy management system Requirement Analysis and Elicitation Document Pharmacy management system Requirement Analysis and Elicitation Document
Pharmacy management system Requirement Analysis and Elicitation Document
 

Similar to Dbms 11: Relational Algebra

Relational Algebra Ch6 (Navathe 4th edition)/ Ch7 (Navathe 3rd edition)
Relational Algebra Ch6 (Navathe 4th edition)/ Ch7 (Navathe 3rd edition)Relational Algebra Ch6 (Navathe 4th edition)/ Ch7 (Navathe 3rd edition)
Relational Algebra Ch6 (Navathe 4th edition)/ Ch7 (Navathe 3rd edition)Raj vardhan
 
Chapter-6 Relational Algebra
Chapter-6 Relational AlgebraChapter-6 Relational Algebra
Chapter-6 Relational AlgebraKunal Anand
 
Dbms ii mca-ch5-ch6-relational algebra-2013
Dbms ii mca-ch5-ch6-relational algebra-2013Dbms ii mca-ch5-ch6-relational algebra-2013
Dbms ii mca-ch5-ch6-relational algebra-2013Prosanta Ghosh
 
Relation model part 1
Relation model part 1Relation model part 1
Relation model part 1Siti Ismail
 
3. Relational Models in DBMS
3. Relational Models in DBMS3. Relational Models in DBMS
3. Relational Models in DBMSkoolkampus
 
Relational algebra operations
Relational algebra operationsRelational algebra operations
Relational algebra operationsSanthiNivas
 
Database system by VISHAL PATIL
Database system by VISHAL PATILDatabase system by VISHAL PATIL
Database system by VISHAL PATILVishal Patil
 
relational model in Database Management.ppt.ppt
relational model in Database Management.ppt.pptrelational model in Database Management.ppt.ppt
relational model in Database Management.ppt.pptRoshni814224
 
Relational operation final
Relational operation finalRelational operation final
Relational operation finalStudent
 
Unit-II DBMS presentation for students.pdf
Unit-II DBMS presentation for students.pdfUnit-II DBMS presentation for students.pdf
Unit-II DBMS presentation for students.pdfajajkhan16
 
Module 2 - part i
Module   2 - part iModule   2 - part i
Module 2 - part iParthNavale
 

Similar to Dbms 11: Relational Algebra (20)

Cs501 rel algebra
Cs501 rel algebraCs501 rel algebra
Cs501 rel algebra
 
Relational Algebra Ch6 (Navathe 4th edition)/ Ch7 (Navathe 3rd edition)
Relational Algebra Ch6 (Navathe 4th edition)/ Ch7 (Navathe 3rd edition)Relational Algebra Ch6 (Navathe 4th edition)/ Ch7 (Navathe 3rd edition)
Relational Algebra Ch6 (Navathe 4th edition)/ Ch7 (Navathe 3rd edition)
 
Chapter-6 Relational Algebra
Chapter-6 Relational AlgebraChapter-6 Relational Algebra
Chapter-6 Relational Algebra
 
Dbms ii mca-ch5-ch6-relational algebra-2013
Dbms ii mca-ch5-ch6-relational algebra-2013Dbms ii mca-ch5-ch6-relational algebra-2013
Dbms ii mca-ch5-ch6-relational algebra-2013
 
Relation model part 1
Relation model part 1Relation model part 1
Relation model part 1
 
Lllll
LllllLllll
Lllll
 
3. Relational Models in DBMS
3. Relational Models in DBMS3. Relational Models in DBMS
3. Relational Models in DBMS
 
Relational algebra operations
Relational algebra operationsRelational algebra operations
Relational algebra operations
 
Bab 5
Bab 5Bab 5
Bab 5
 
Relational Algebra-23-04-2023.pdf
Relational Algebra-23-04-2023.pdfRelational Algebra-23-04-2023.pdf
Relational Algebra-23-04-2023.pdf
 
Database system by VISHAL PATIL
Database system by VISHAL PATILDatabase system by VISHAL PATIL
Database system by VISHAL PATIL
 
relational model in Database Management.ppt.ppt
relational model in Database Management.ppt.pptrelational model in Database Management.ppt.ppt
relational model in Database Management.ppt.ppt
 
3.ppt
3.ppt3.ppt
3.ppt
 
DBMS 7 | Relational Query Language
DBMS 7 | Relational Query LanguageDBMS 7 | Relational Query Language
DBMS 7 | Relational Query Language
 
Relation Algebra
Relation AlgebraRelation Algebra
Relation Algebra
 
Relational operation final
Relational operation finalRelational operation final
Relational operation final
 
Unit-II DBMS presentation for students.pdf
Unit-II DBMS presentation for students.pdfUnit-II DBMS presentation for students.pdf
Unit-II DBMS presentation for students.pdf
 
Lec02
Lec02Lec02
Lec02
 
Module 2 - part i
Module   2 - part iModule   2 - part i
Module 2 - part i
 
relational algebra
relational algebrarelational algebra
relational algebra
 

More from Amiya9439793168

Dbms 14: Relational Calculus
Dbms 14: Relational CalculusDbms 14: Relational Calculus
Dbms 14: Relational CalculusAmiya9439793168
 
Dbms 13: Query Using Relational Algebra
Dbms 13: Query Using Relational AlgebraDbms 13: Query Using Relational Algebra
Dbms 13: Query Using Relational AlgebraAmiya9439793168
 
Dbms 10: Conversion of ER model to Relational Model
Dbms 10: Conversion of ER model to Relational ModelDbms 10: Conversion of ER model to Relational Model
Dbms 10: Conversion of ER model to Relational ModelAmiya9439793168
 
Dbms 9: Relational Model
Dbms 9: Relational ModelDbms 9: Relational Model
Dbms 9: Relational ModelAmiya9439793168
 
Dbms 8: Enhanced ER Model
Dbms 8: Enhanced ER ModelDbms 8: Enhanced ER Model
Dbms 8: Enhanced ER ModelAmiya9439793168
 
Dbms 3: 3 Schema Architecture
Dbms 3: 3 Schema ArchitectureDbms 3: 3 Schema Architecture
Dbms 3: 3 Schema ArchitectureAmiya9439793168
 
Introduction to Database Management System
Introduction to Database Management SystemIntroduction to Database Management System
Introduction to Database Management SystemAmiya9439793168
 
Dbms 7: ER Diagram Design Issue
Dbms 7: ER Diagram Design IssueDbms 7: ER Diagram Design Issue
Dbms 7: ER Diagram Design IssueAmiya9439793168
 

More from Amiya9439793168 (11)

Dbms 14: Relational Calculus
Dbms 14: Relational CalculusDbms 14: Relational Calculus
Dbms 14: Relational Calculus
 
Dbms 13: Query Using Relational Algebra
Dbms 13: Query Using Relational AlgebraDbms 13: Query Using Relational Algebra
Dbms 13: Query Using Relational Algebra
 
Dbms 12: Join
Dbms 12: JoinDbms 12: Join
Dbms 12: Join
 
Dbms 10: Conversion of ER model to Relational Model
Dbms 10: Conversion of ER model to Relational ModelDbms 10: Conversion of ER model to Relational Model
Dbms 10: Conversion of ER model to Relational Model
 
Dbms 9: Relational Model
Dbms 9: Relational ModelDbms 9: Relational Model
Dbms 9: Relational Model
 
Dbms 8: Enhanced ER Model
Dbms 8: Enhanced ER ModelDbms 8: Enhanced ER Model
Dbms 8: Enhanced ER Model
 
Dbms 6: ER Modeling
Dbms 6: ER ModelingDbms 6: ER Modeling
Dbms 6: ER Modeling
 
Dbms 3: 3 Schema Architecture
Dbms 3: 3 Schema ArchitectureDbms 3: 3 Schema Architecture
Dbms 3: 3 Schema Architecture
 
Dbms 2: Data Model
Dbms 2: Data ModelDbms 2: Data Model
Dbms 2: Data Model
 
Introduction to Database Management System
Introduction to Database Management SystemIntroduction to Database Management System
Introduction to Database Management System
 
Dbms 7: ER Diagram Design Issue
Dbms 7: ER Diagram Design IssueDbms 7: ER Diagram Design Issue
Dbms 7: ER Diagram Design Issue
 

Recently uploaded

Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionDr.Costas Sachpazis
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxwendy cai
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...asadnawaz62
 
Risk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfRisk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfROCENODodongVILLACER
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
Arduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptArduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptSAURABHKUMAR892774
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSCAESB
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxDeepakSakkari2
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024Mark Billinghurst
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxbritheesh05
 
DATA ANALYTICS PPT definition usage example
DATA ANALYTICS PPT definition usage exampleDATA ANALYTICS PPT definition usage example
DATA ANALYTICS PPT definition usage examplePragyanshuParadkar1
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxKartikeyaDwivedi3
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfAsst.prof M.Gokilavani
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineeringmalavadedarshan25
 
EduAI - E learning Platform integrated with AI
EduAI - E learning Platform integrated with AIEduAI - E learning Platform integrated with AI
EduAI - E learning Platform integrated with AIkoyaldeepu123
 
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)dollysharma2066
 
Work Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvWork Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvLewisJB
 

Recently uploaded (20)

Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptx
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...
 
Risk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfRisk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdf
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
Arduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptArduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.ppt
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentation
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptx
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptx
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
DATA ANALYTICS PPT definition usage example
DATA ANALYTICS PPT definition usage exampleDATA ANALYTICS PPT definition usage example
DATA ANALYTICS PPT definition usage example
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptx
 
POWER SYSTEMS-1 Complete notes examples
POWER SYSTEMS-1 Complete notes  examplesPOWER SYSTEMS-1 Complete notes  examples
POWER SYSTEMS-1 Complete notes examples
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineering
 
EduAI - E learning Platform integrated with AI
EduAI - E learning Platform integrated with AIEduAI - E learning Platform integrated with AI
EduAI - E learning Platform integrated with AI
 
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
 
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
 
Work Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvWork Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvv
 

Dbms 11: Relational Algebra

  • 1. Dr. Amiya Ranjan Panda Assistant Professor [II] School of Computer Engineering, Kalinga Institute of Industrial Technology (KIIT), Deemed to be University,Odisha Relational Algebra KALINGA INSTITUTE OF INDUSTRIAL TECHNOLOGY School Of Computer Engineering 4 Credit Lecture Note 11
  • 2. Chapter Contents q Query Language q Relational Algebra q SELECT Operator (σ) q PROJECT Operator (π) q Composition of Relational Operators q RENAME Operator (ρ) q Union Compatibility q UNION Operator (∪) q DIFFERENCE Operator (-) q Cartesian Product Operator (×) q Intersection Operator (∩) q JOIN Operator (⋉ ⋊ ) q Division Operator (÷) q Assignment Operator (←) 2
  • 3. Ø Language in which user requests information from the database are: ü Procedural language ü Nonprocedural language Ø The categories of different languages are: üSQL üRelational Algebra üRelational Calculus ØTuple Relational Calculus ØDomain Relational Calculus 3 Query Language
  • 4. Ø Relational algebra is a procedural language for manipulating relations. Relational algebra operations manipulate relations. That is, these operations use one or two existing relations to create a new relation: Ø Fundamental operators ü Unary: SELECT, PROJECT, RENAME ü Binary: UNION, SET DIFFERENCE, CARTESIAN PRODUCT Ø Secondary operators ü INTERSECTION, NATURAL JOIN, DIVISION, and ASSIGNMENT 4 Relational Algebra
  • 5. Ø The relational schemas used for different operations are: ü Customer(cust_name, cust_street, cust_city) used to store customer details ü Branch(branch_name, branch_city, assets) used to store branch details üAccount(acc_no, branch_name, balance) stores the account details ü Loan(loan_no, branch_name, amount) stores the loan details ü Depositor(cust_name, acc_no) stores the details about the customers’ account ü Borrower(cust_name, loan_no) used to store the details about the customers’ loan 5 Relational Algebra…
  • 6. Ø SELECT operation is used to create a relation from another relation by selecting only those tuples or rows from the original relation that satisfy a specified condition. It is denoted by sigma (σ) symbol. The predicate appears as a subscript to σ. Ø The argument relation is in parenthesis after the σ. The result is a relation that has the same attributes as the relation specified in <relation-name>. The general syntax of select operator is: σ <selection−condition> (<relation name>) Ø Query: Find the details of the loans taken from ’Bhubaneswar Main’ branch. σ branch_name=′ BhubaneswarMain′ (Loan) ü The operators used in selection predicate may be: =, 6=, <, ≤, >, ≥. ü Different predicates can be combined into a larger predicate by using the connectors like: AND(V), OR(W), NOT(¬) 6 SELECT Operator (σ)
  • 7. 7 SELECT Operator (σ)… Loan Ø σ branch_name=′ BhubaneswarMain′ (Loan) Ø σ branch_name=′ BhubaneswarMain′ AND amount >10,000,000 (Loan) loan_no branch_name amount L201 Bhubaneswar Main 50,000,000.00 L202 Bhubaneswar Main 5,000,000.00 L203 Mumbai Main 100,000,000.00 L204 Juhu 60,000,000.00 loan_no branch_name amount L201 L202 Bhubaneswar Main Bhubaneswar Main 50,000,000.00 5,000,000.00 loan_no branch_name amount L201 Bhubaneswar Main 50,000,000.00
  • 8. Ø PROJECT operation can be thought of as eliminating unwanted columns. It eliminates the duplicate rows. It is denoted by pie (π) symbol. The attributes needed to be appeared in the resultant relation appear as subscript to π. Ø The argument relation follows in parenthesis. The general syntax of project operator is: π <attribute−list > (<relation name>) Ø Query: Find the loan numbers and respective loan amounts. π loan_no,amount (Loan) 8 PROJECT Operator(π) Loan π loan_no, amount (Loan) loan_no branch_name amount L201 Bhubaneswar Main 50,000,000.00 L202 Bhubaneswar Main 5,000,000.00 L203 Mumbai Main 100,000,000.00 L204 Juhu 60,000,000.00 loan_no amount L201 50,000,000.00 L202 5,000,000.00 L203 100,000,000.00 L204 60,000,000.00
  • 9. Ø Relational algebra operators can be composed together into a relational algebra expression to answer the complex queries. Ø Q: Find the name of the customers who live in Bhubaneswar. 9 Composition of Relational Operators Customer π cust _name (σ cust _city =′ Bhubaneswar ′ (Customer)) cust_name cust_street cust_city Rishi Sarthak Manas Ramesh Mahesh India Gate M. G. Road Shastri Nagar M. G. Road Juhu New Delhi Bangalore Bhubaneswar Bhubaneswar Mumbai cust_name Manas Ramesh
  • 10. Ø The results of relational algebra expressions do not have a name that can be used to refer them. It is useful to be able to give them names; the rename operator is used for this purpose. It is denoted by rho (ρ) symbol. Ø The general syntax of rename operator is: ρ X (E) Ø Assume E is a relational-algebra expression with arity n. The second form of rename operation is: ρ X (b1 ,b2 ,...bn ) (E) Ø π cust _name (σ cust _city =′ Bhubaneswar ′ (Customer)) can be written as: 1. ρCustomer _Bhubaneswar (σ cust _city =′ Bhubaneswar ′ (Customer)) 2. π cust_name (Customer_Bhubaneswar) 10 RENAME Operator(ρ)
  • 11. Ø The different forms of the rename operation for renaming the relation are: a. ρ S (R) b. ρ S(b1 ,b2 ,...bn ) (R) c. ρ (b ,b ,...b ) (R) Ø For example, the attributes of Customer (cust_name, cust_street, cust_city) can be renamed as: ρ (name,street,city) (Customer) 11 RENAME Operator(ρ)…
  • 12. Ø To perform the set operations such as UNION, DIFFERENCE and INTERSECTION, the relations need to be union compatible for the result to be a valid relation. Ø Two relations R1(a1,a2,... an ) and R2(b1,b2,... bm ) are union compatible iff: ü n = m, i.e. both relations have same arity ü dom(ai ) = dom(bi ) for 1 ≤ i ≤ n 12 Union Compatibility
  • 13. Ø The union operation is used to combine data from two relations. It is denoted by union(∪) symbol. The union of two relations R1(a1,a2,... an) and R2(b1,b2,... bn) is a relation R3 (c1,c2,... cn) such that: dom(ci) = dom(ai) ∪dom(bi), 1 ≤ i ≤ n Ø R1 ∪R2 is a relation that includes all tuples that are either present in R1 or R2 or in both without duplicate tuples. Ø π cust_name (Depositor) ∪ π cust_name (Borrower) 13 UNION Operator (∪)
  • 14. Ø The difference operation is used to identify the rows that are in one relation and not in another. It is denoted as (-) symbol. The difference of two relations R1(a1,a2,... an ) and R2(b1,b2,... bn ) is a relation R3 (c1,c2,... cn ) such that: dom(ci ) = dom(ai ) - dom(bi ), 1 ≤ i ≤ n Ø R1 - R2 is a relation that includes all tuples that are in R1, but not in R2. Ø π cust_name (Depositor) - π cust_name (Borrower) 14 DIFFERENCE Operator(-)
  • 15. Ø The Cartesian product of two relations R1(a1,a2,... an ) with cardinality i and R2(b1,b2,... bm ) with cardinality j is a relation R3 with ü degree k = n + m, ü cardinality i*j and ü attributes (a1,a2,... an , b1,b2,... bm )) Ø R1 × R2 is a relation that includes all the possible combinations of tuples from R1 and R2. The Cartesian product is used to combine information from any two relations. Ø It is not a useful operation by itself; but is used in conjuction with other operations. 15 Cartesian Product Operator(×)
  • 17. Ø Query: Find out the customer and their loan details taken from Bhubaneswar Main branch. A n s : σ b r a n c h _ n a m e = ′ B h u b a n e s w a r M a i n ′ A N D Borrower.loan_no=Loan.loan_no (Borrower ×Loan) 17 Cartesian Product Operator(×)…
  • 18. Ø The intersection operation is used to identify the rows that are common to two relations. It is denoted by (∩) symbol. The intersection of two relations R1 (a1,a2,... an ) and R2 (b1,b2,... bn ) is a relation R3 (c1,c2,... cn ) such that… dom (ci ) = dom (ai ) ∩ dom (bi ), 1 ≤ i ≤ n Ø R1 ∩ R2 is a relation that includes all tuples that are present in both R1 and R2. Ø The intersection operation can be rewritten by a pair of set difference operations as R ∩ S = R - (R - S). π cust_name (Depositor) ∩ π cust_name (Borrower) 18 Intersection Operator(∩)
  • 19. Ø The join is a binary operation that is used to combine certain selections and a Cartesian product into one operation. It is denoted by join (⋊ ⋉ ) symbol. Ø The join operation forms a Cartesian product of its two arguments, performs a selection forcing equality on those attributes that appear in both relations, and finally removes the duplicate attributes. Ø Query: Find the names of customers who have a loan at the bank, along with the loan number and the loan amount ? Ans: This query can be solved by using the PROJECT, SELECT and CARTESIAN PRODUCT operators as: Π cust _name,Loan.loan_no,amount (σ Borrower .loan_no = Loan.loan_no (Borrower ×Loan)) Ø This same expression can be simplified by using the JOIN as: π cust_name, loan_no, amount (Borrower ⋊⋉ Loan)) 19 JOIN Operator(⋉)
  • 21. Ø The division operation creates a new relation by selecting the rows in one relation that match every row in another relation. The division operation requires that we look at an entire relation at once. It is denoted by division (÷) symbol. Ø Let A, B, C are three relations and we desire B ÷ C to give A as the result. This operation is possible iff: ü The columns of C must be a subset of the columns of B. The columns of A are all and only those columns of B that are not columns of C ü A row is placed in A if and only if it is associated with B and with every row of C Ø The division operation is the reverse of the Cartesian product operation as: B = (B × C) ÷ C. Ø Division operator is suited to queries that include the phrase every or all as part of the condition. 21 Division Operator (÷)
  • 23. Ø It works like assignment in a programming language. In relational algebra, the assignment operator gives a name to a relation. It is denoted by (←) symbol. Ø Assignment must always be made to a temporary relation variable. The result of the right of the ← symbol is assigned to the relation variable on the left of the ← symbol. Ø With the assignment operator, a query can be written as a sequential program consisting of: üa series of assignment, üfollowed by an expression whose value is displayed as a result of the query π cust_name,branch_name (Depositor ⋊⋉ Account) ÷ π branch_name (σ branch_city=′Mumbai′ (Branch)) can be simplified as: Temp1 ← π cust_name,branch_name (Depositor ⋊⋉ Account) Temp2 ← π branch_name (σ branch_city=′Mumbai′ (Branch)) Result = Temp1 ÷ Temp2 23 Assignment Operator(←)
  • 24. 24