0% found this document useful (0 votes)
34 views

Lecture Notes For DBMS and Data Mining and Data Warehousing: Relational Algebra

This document contains lecture notes on relational algebra operations including selection, projection, cross-product, set difference, union, intersection, and division. It defines each operation and provides examples to illustrate how they work and how operations can be composed together. Key relational algebra operations covered are selection, projection, union, intersection, and set difference. Example relations are used to demonstrate how each operation transforms and combines relations.
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views

Lecture Notes For DBMS and Data Mining and Data Warehousing: Relational Algebra

This document contains lecture notes on relational algebra operations including selection, projection, cross-product, set difference, union, intersection, and division. It defines each operation and provides examples to illustrate how they work and how operations can be composed together. Key relational algebra operations covered are selection, projection, union, intersection, and set difference. Example relations are used to demonstrate how each operation transforms and combines relations.
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

Lecture Notes For DBMS and Data Mining and Data Warehousing

Lecture 10
Relational Algebra:
 Basic operations:
o Selection (σ) Selects a subset of rows from relation.
o Projection (π) Selects a subset of columns from relation.
o Cross-product (×) Allows us to combine two relations.
o Set-difference () Tuples in reln. 1, but not in reln. 2.
o Union (U) Tuples in reln. 1 and in reln. 2.
o Rename( ρ) Use new name for the Tables or fields.
 Additional operations:
o Intersection (∩), join( ), division(÷): Not essential, but (very!) useful.
 Since each operation returns a relation, operations can be composed! (Algebra is
“closed”.)
Projection
 Deletes attributes that are not in projection list.
 Schema of result contains exactly the fields in the projection list, with the same names
that they had in the (only) input relation. ( Unary Operation)
 Projection operator has to eliminate duplicates! (as it returns a relation which is a set)
o Note: real systems typically don’t do duplicate elimination unless the user
explicitly asks for it. (Duplicate values may be representing different real world
entity or relationship)
Consider the BOOK table:
Acc-No Title Author
100 “DBMS” “Silbershatz”
200 “DBMS” “Ramanuj”
300 “COMPILER” “Silbershatz”
400 “COMPILER” “Ullman”
500 “OS” “Sudarshan”
600 “DBMS” “Silbershatz”

πTitle(BOOK) =
Title
“DBMS”
“COMPILER”
“OS”

Selection
 Selects rows that satisfy selection condition.
 No duplicates in result! (Why?)
 Schema of result identical to schema of (only) input relation.
 Result relation can be the input for another relational algebra operation! (Operator
composition.)
σAcc-no>300(BOOK) =
Acc-No Title Author
400 “COMPILER” “Ullman”
500 “OS” “Sudarshan”
600 “DBMS” “Silbershatz”

Department of Electrical and Electronics By: Sulabh Bansal


Lecture Notes For DBMS and Data Mining and Data Warehousing

σTitle=”DBMS”(BOOK)=
Acc-No Title Author
100 “DBMS” “Silbershatz”
200 “DBMS” “Ramanuj”
600 “DBMS” “Silbershatz”

πAcc-no (σTitle=”DBMS” (BOOK))=


Acc-No
100
200
600

Union, Intersection, Set-Difference


 All of these operations take two input relations, which must be union-compatible:
o Same number of fields.
o `Corresponding’ fields have the same type.
 What is the schema of result?
Consider:
Borrower Depositor
Cust-name Loan-no Cust-name Acc-no
Ram L-13 Suleman A-100
Shyam L-30 Radheshyam A-300
Suleman L-42 Ram A-401

List of customers who are either borrower or depositor at bank= πCust-name (Borrower) U
πCust-name (Depositor)=
Cust-name
Ram
Shyam
Suleman
Radeshyam

Customers who are both borrowers and depositors = πCust-name (Borrower) ∩ πCust-name
(Depositor)=
Cust-name
Ram
Suleman

Customers who are borrowers but not depositors = πCust-name (Borrower)  πCust-name
(Depositor)=
Cust-name
Shyam

Department of Electrical and Electronics By: Sulabh Bansal

You might also like