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

Lecture Notes For DBMS: Relational Algebra

This document contains lecture notes on relational algebra for database management systems (DBMS). It defines basic relational algebra operations like selection, projection, cross-product, set operations, and additional operations like join and division. It provides examples of how to use projection and selection operations on a sample BOOKS table, and discusses union, intersection, and difference set operations on BORROWER and DEPOSITOR tables.
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

Lecture Notes For DBMS: Relational Algebra

This document contains lecture notes on relational algebra for database management systems (DBMS). It defines basic relational algebra operations like selection, projection, cross-product, set operations, and additional operations like join and division. It provides examples of how to use projection and selection operations on a sample BOOKS table, and discusses union, intersection, and difference set operations on BORROWER and DEPOSITOR tables.
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

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 dont 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 Computer Science


By: Dipendra Air
Lecture Notes For DBMS

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 Computer Science


By: Dipendra Air

You might also like