0% found this document useful (0 votes)
0 views9 pages

DBMS 12

The document provides class notes on relational algebra, detailing its role as a procedural query language used to manipulate data in relational databases. It explains the types of query languages, the characteristics and operations of relational algebra, including basic and derived operations, and specific operators like selection and projection. Additionally, it highlights important points regarding the behavior of these operators and their equivalence to SQL commands.

Uploaded by

tapatapdobo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views9 pages

DBMS 12

The document provides class notes on relational algebra, detailing its role as a procedural query language used to manipulate data in relational databases. It explains the types of query languages, the characteristics and operations of relational algebra, including basic and derived operations, and specific operators like selection and projection. Additionally, it highlights important points regarding the behavior of these operators and their equivalence to SQL commands.

Uploaded by

tapatapdobo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Government of West Bengal

Dr. Meghnad Saha Institute of Technology, Haldia


Department of Computer Science & Technology
Class Notes on Relational Algebra

After designing of database, i.e., ER diagram design then converting it into relational model
followed by normalization and indexing, now task is how to store, retrieve and modify data
in database.
Query Language: Languages in which user request some information from database.
Query language can be two types:
1. Procedural Query Language
2. Non-procedural Query Language

Procedural Query Language:


User Instruct the system to perform a sequence of operations in order to produce desire
result. User tells what data to be retrieved and how to be retrieved.

Non-procedural Query Language:


Users describe the desire information without giving the specific procedure for obtaining
that information.

 In practice, we use RDBMS (practical implementation of relational model)


 SQL is used to write query on it.
 So relational is a conceptual/theoretical framework and RDBMS is its implementation.
 Relational algebra (procedural) and relational calculus (non-procedural) are
mathematical system or query language used on relational model.

Prepared by Sukanta Singh, Lecturer in CST Page 1 of 18


Government of West Bengal
Dr. Meghnad Saha Institute of Technology, Haldia
Department of Computer Science & Technology
Class Notes on Relational Algebra

Relational Algebra-

Relational Algebra is a procedural query language which takes a relation as an


input and generates a relation as an output.

Characteristics-
Following are the important characteristics of relational operators-
 Relational algebra is one of the two formal query language associated with relational
model.
 Like any other mathematical system is defined a number of operators and use relations
(tables) as operands.
 Every operator in relational algebra takes one or two relations as an input argument and
generates a single relation as a result without a name.
 The table produced by a relational operator has all the properties of a relational model.
 Relational algebra does not consider duplicity as it is based on set theory.
 In each query we describe a step by step procedure for computing the desired result. So
it is a procedural query language.
 No use of English keywords.

Types of operations in relational algebra:


We have divided these operations in two categories:
1. Basic Operations
2. Derived Operations
Basic/Fundamental Operations:
1. Select (σ)
2. Project (∏)
3. Union (∪)
4. Set Difference (-)
5. Cartesian product (X)
6. Rename (ρ)
Derived Operations:
1. Natural Join (⋈)
2. Left, Right, Full outer join (⟕, ⟖, ⟗)
3. Intersection (∩)
4. Division (÷)

Prepared by Sukanta Singh, Lecturer in CST Page 2 of 18


Government of West Bengal
Dr. Meghnad Saha Institute of Technology, Haldia
Department of Computer Science & Technology
Class Notes on Relational Algebra

Selection Operator-

 Selection Operator (σ) is a unary operator in relational algebra so it can take only one
table at a time that performs a selection operation.
 It is a fundamental operator.
 It selects those rows or tuples from the relation that satisfies the selection condition.
 It has same function as of where clause in SQL.
 Minimum number of tuples selected is zero.
 Maximum number of tuples selected is all of the tuples in a relation.
Syntax-
σ<selection_condition/predicate>(R)

Examples- Consider the following Student table -

S_ID Name Branch


1 A CST
2 B ME
3 C CST
4 D CST
5 E EE
6 F EIE
7 G CE

Select those tuples whose branch name is CST.

σBrnach=CST(Student)

More examples -

 Select tuples from a relation “Books” where subject is “database”


σsubject = “database” (Books)
 Select tuples from a relation “Books” where subject is “database” and price is “450”
σsubject = “database” ∧ price = “450” (Books)
 Select tuples from a relation “Books” where subject is “database” and price is “450” or
have a publication year after 2010
σsubject = “database” ∧ price = “450” ∨ year >”2010″ (Books)

Prepared by Sukanta Singh, Lecturer in CST Page 3 of 18


Government of West Bengal
Dr. Meghnad Saha Institute of Technology, Haldia
Department of Computer Science & Technology
Class Notes on Relational Algebra

Prepared by Sukanta Singh, Lecturer in CST Page 4 of 18


Government of West Bengal
Dr. Meghnad Saha Institute of Technology, Haldia
Department of Computer Science & Technology
Class Notes on Relational Algebra

Important Points-

Point-01:

 We may use logical operators like ∧ Logical AND , ∨ Logical OR , ! [Logical NOT] and
relational operators like = , ≠ , > , < , <= , >= with the selection condition.

Point-02:

 Selection operator only selects the required tuples according to the selection
condition.
 It does not display the selected tuples.
 To display the selected tuples, projection operator is used.

Point-03:

 Selection operator always selects the entire tuple. It cannot select a section or part of
a tuple.

Point-04:

 Selection operator is commutative in nature i.e.


σ A∧B (R) = σ B∧A (R)
OR
σ B (σ A(R)) = σ A (σ B(R))

Point-05:

 Degree of the relation from a selection operation is same as degree of the input
relation.

Point-06:

 The number of rows returned by a selection operation is obviously less than or equal
to the number of rows in the original table.
Thus,
 Minimum Cardinality = 0
 Maximum Cardinality = |R|

Prepared by Sukanta Singh, Lecturer in CST Page 5 of 18


Government of West Bengal
Dr. Meghnad Saha Institute of Technology, Haldia
Department of Computer Science & Technology
Class Notes on Relational Algebra

Projection Operator-
 Projection Operator (π) is a unary operator in relational algebra which take one table
at a time and performs a projection operation.
 It is also fundamental operator.
 It displays the columns of a relation or table based on the specified attributes.
 It works as of select clause in SQL.
Syntax-

π<attribute list/column_name>(R)

Example-
Consider the following Student relation-

ID Name Subject Age

100 Ashish Maths 19

200 Rahul Science 20

300 Naina Physics 20

400 Sameer Chemistry 21


Student
Then, we have-
Result for Query πName, Age(Student)-

Name Age

Ashish 19

Rahul 20

Naina 20

Sameer 21

Prepared by Sukanta Singh, Lecturer in CST Page 6 of 18


Government of West Bengal
Dr. Meghnad Saha Institute of Technology, Haldia
Department of Computer Science & Technology
Class Notes on Relational Algebra

Result for Query πID , Name(Student)-

ID Name

100 Ashish

200 Rahul

300 Naina

400 Sameer

Some more examples -

Prepared by Sukanta Singh, Lecturer in CST Page 7 of 18


Government of West Bengal
Dr. Meghnad Saha Institute of Technology, Haldia
Department of Computer Science & Technology
Class Notes on Relational Algebra

Prepared by Sukanta Singh, Lecturer in CST Page 8 of 18


Government of West Bengal
Dr. Meghnad Saha Institute of Technology, Haldia
Department of Computer Science & Technology
Class Notes on Relational Algebra

Important Points-

Point-01:
 The degree of output relation (number of columns present) is equal to the number of
attributes mentioned in the attribute list.
Point-02:
 Projection operator automatically removes all the duplicates while projecting the
output relation.
 So, cardinality of the original relation and output relation may or may not be same.

 If there are no duplicates in the original relation, then the cardinality will remain
same otherwise it will surely reduce.
Point-03:
 If attribute list is a super key on relation R, then we will always get the same number
of tuples in the output relation.
 This is because then there will be no duplicates to filter.

Point-04:
 Projection operator does not obey commutative property i.e.

π <list2> (π <list1> (R)) ≠ π <list1> (π <list2> (R))


Point-05:
 Following expressions are equivalent because both finally projects columns of list-1

π <list1> (π <list2> (R)) = π <list1> (R)


Point-06:
 Selection Operator performs horizontal partitioning of the relation.

 Projection operator performs vertical partitioning of the relation.

Point-07:
 There is only one difference between projection operator of relational algebra and
SELECT operation of SQL.
 Projection operator does not allow duplicates while SELECT operation allows
duplicates.
 To avoid duplicates in SQL, we use “distinct” keyword and write SELECT distinct.

 Thus, projection operator of relational algebra is equivalent to SELECT operation of


SQL.

Prepared by Sukanta Singh, Lecturer in CST Page 9 of 18

You might also like