The Wayback Machine - https://web.archive.org/web/20240906164541/https://www.geeksforgeeks.org/introduction-of-relational-algebra-in-dbms/
Open In App

Introduction of Relational Algebra in DBMS

Last Updated : 29 Jul, 2024
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

Pre-Requisite: Relational Model in DBMS

Relational Algebra is a procedural query language. Relational algebra mainly provides a theoretical foundation for relational databases and SQL. The main purpose of using Relational Algebra is to define operators that transform one or more input relations into an output relation. Given that these operators accept relations as input and produce relations as output, they can be combined and used to express potentially complex queries that transform potentially many input relations (whose data are stored in the database) into a single output relation (the query results). As it is pure mathematics, there is no use of English Keywords in Relational Algebra and operators are represented using symbols.

Fundamental Operators

These are the basic/fundamental operators used in Relational Algebra.

  1. Selection(σ)
  2. Projection(π)
  3. Union(U)
  4. Set Difference(-)
  5. Set Intersection(âˆĐ)
  6. Rename(ρ)
  7. Cartesian Product(X)

1. Selection(σ): It is used to select required tuples of the relations.

Example:

A        B        C       
1 2 4
2 2 3
3 2 3
4 3 4

For the above relation, σ(c>3)R will select the tuples which have c more than 3.

A        B        C       
1 2 4
4 3 4

Note: The selection operator only selects the required tuples but does not display them. For display, the data projection operator is used. 

2. Projection(π): It is used to project required column data from a relation. 

Example: Consider Table 1. Suppose we want columns B and C from Relation R.

π(B,C)R will show following columns.
B        C       
2 4
2 3
3 4

Note: By Default, projection removes duplicate data.   

3. Union(U): Union operation in relational algebra is the same as union operation in set theory.

Example:

                                                                                                                         FRENCH

Student_Name     Roll_Number    
Ram 01
Mohan 02
Vivek 13
Geeta 17

                                                                                                                          GERMAN

Student_Name     Roll_Number    
Vivek 13
Geeta 17
Shyam 21
Rohan 25

Consider the following table of Students having different optional subjects in their course.

π(Student_Name)FRENCH U π(Student_Name)GERMAN
Student_Name
Ram
Mohan
Vivek
Geeta
Shyam
Rohan

Note: The only constraint in the union of two relations is that both relations must have the same set of Attributes.   

4. Set Difference(-): Set Difference in relational algebra is the same set difference operation as in set theory.

Example: From the above table of FRENCH and GERMAN, Set Difference is used as follows

π(Student_Name)FRENCH - π(Student_Name)GERMAN
Student_Name
Ram
Mohan

Note: The only constraint in the Set Difference between two relations is that both relations must have the same set of Attributes.   

5. Set Intersection(âˆĐ): Set Intersection in relational algebra is the same set intersection operation in set theory.

Example: From the above table of FRENCH and GERMAN, the Set Intersection is used as follows

π(Student_Name)FRENCH âˆĐ π(Student_Name)GERMAN
Student_Name
Vivek
Geeta

Note: The only constraint in the Set Difference between two relations is that both relations must have the same set of Attributes.  

6. Rename(ρ): Rename is a unary operation used for renaming attributes of a relation.

 ρ(a/b)R will rename the attribute 'b' of the relation by 'a'.   

7. Cross Product(X): Cross-product between two relations. Let’s say A and B, so the cross product between A X B will result in all the attributes of A followed by each attribute of B. Each record of A will pair with every record of B.

Example: 

                                                                                                                                   A

Name      Age      Sex      
Ram 14 M
Sona 15 F
Kim 20 M

                                                                                                                             B

ID      Course     
1 DS
2 DBMS

                                                                                                                            A X B

Name      Age      Sex      ID       Course     
Ram 14 M 1 DS
Ram 14 M 2 DBMS
Sona 15 F 1 DS
Sona 15 F 2 DBMS
Kim 20 M 1 DS
Kim 20 M 2 DBMS

Note: If A has ‘n’ tuples and B has ‘m’ tuples then A X B will have ‘ n*m ‘ tuples.   

Derived Operators

These are some of the derived operators, which are derived from the fundamental operators.

  1. Natural Join(⋈)
  2. Conditional Join

1. Natural Join(⋈): Natural join is a binary operator. Natural join between two or more relations will result in a set of all combinations of tuples where they have an equal common attribute. 

Example:

                                                                                                                        EMP

Name       ID          Dept_Name    
A 120 IT
B 125 HR
C 110 Sales
D 111 IT

                                                                                                                   DEPT

Dept_Name      Manager     
Sales Y
Production Z
IT A

Natural join between EMP and DEPT with condition :

EMP.Dept_Name = DEPT.Dept_Name           

                                                                                                   EMP ⋈ DEPT

Name      ID          Dept_Name      Manager     
A 120 IT A
C 110 Sales Y
D 111 IT A

2. Conditional Join: Conditional join works similarly to natural join. In natural join, by default condition is equal between common attributes while in conditional join we can specify any condition such as greater than, less than, or not equal. 

Example:

                                                                                                                                R

ID      Sex      Marks    
1 F 45
2 F 55
3 F 60

                                                                                                                               S

ID      Sex      Marks    
10 M 20
11 M 22
12 M 59

Join between R and S with condition  R.marks >= S.marks

R.ID    R.Sex    R.Marks    S.ID    S.Sex    S.Marks   
1 F 45 10 M 20
1 F 45 11 M 22
2 F 55 10 M 20
2 F 55 11 M 22
3 F 60 10 M 20
3 F 60 11 M 22
3 F 60 12 M 59

Relational Calculus

As Relational Algebra is a procedural query language, Relational Calculus is a non-procedural query language. It basically deals with the end results. It always tells me what to do but never tells me how to do it.

There are two types of Relational Calculus

  1. Tuple Relational Calculus(TRC)
  2. Domain Relational Calculus(DRC)

In-depth articles: 
Basic-operators-in-relational-algebra                                          
Extended Relational Algebra Operators 

Following are the Previous Year’s Gate Questions 
https://www.geeksforgeeks.org/gate-gate-cs-2012-question-50/ 
https://www.geeksforgeeks.org/gate-gate-cs-2012-question-43/ 



Previous Article
Next Article

Similar Reads

Difference between Relational Algebra and Relational Calculus
Both Relational Algebra and Relational Calculus are formal query languages. Relational Algebra: Relational Algebra is a procedural language. In Relational Algebra, The order is specified in which the operations have to be performed. In Relational Algebra, frameworks are created to implement the queries. The basic operation included in relational al
3 min read
Introduction of Relational Model and Codd Rules in DBMS
Pre-Requisite: Relational Model in DBMS It was proposed by Dr. E.F. Codd. It uses the concept of relations to represent each and every file. Relations are Two-Dimensional Tables. It is easy to implement and easy to simplification in the operations to manipulate the data. This is the most popular data model. It is simple to implement. It uses the pr
12 min read
Difference between Tuple Relational Calculus (TRC) and Domain Relational Calculus (DRC)
1. Tuple Relational Calculus (TRC) : A tuple relational calculus is a non-procedural query language that specifies to select of the tuples in a relation. It can select the tuples with a range of values or tuples for certain attribute values etc. The resulting relation can have one or more tuples. Notation : {T | P (T)} or {T | Condition (T)} where
3 min read
Example Queries on Relational Algebra
Given below are a few examples of a database and a few queries based on that. (1). Suppose there is a banking database which comprises following tables : Customer(Cust_name, Cust_street, Cust_city) Branch(Branch_name, Branch_city, Assets) Account (Branch_name, Account_number, Balance) Loan(Branch_name, Loan_number, Amount) Depositor(Cust_name, Acco
1 min read
PROJECT Operation in Relational Algebra
Prerequisite - Relational Algebra Project operation selects (or chooses) certain attributes discarding other attributes. The Project operation is also known as vertical partitioning since it partitions the relation or table vertically discarding other columns or attributes. Notation: πA(R) where 'A' is the attribute list, it is the desired set o
2 min read
Cartesian Product Operation in Relational Algebra
Prerequisite - Relational Algebra We already are aware of the fact that relations are nothing but a set of tuples, and here we will have 2 sets of tuples. On applying CARTESIAN PRODUCT on two relations that is on two sets of tuples, it will take every tuple one by one from the left set(relation) and will pair it up with all the tuples in the right
3 min read
RENAME (ρ) Operation in Relational Algebra
Prerequisites - Introduction of Relational Algebra in DBMS, Basic Operators in Relational Algebra The RENAME operation is used to rename the output of a relation. Sometimes it is simple and suitable to break a complicated sequence of operations and rename it as a relation with different names. Reasons to rename a relation can be many, like - We may
2 min read
Set Difference Operator in Relational Algebra
Relational Algebra is used to play with the data stored in relational databases. Relational Algebra has many operations to play with tables. One of the fundamental operations is set difference. This article will discuss Set Difference, its condition, and its examples. Key Terms Used in Set Difference Operator Relation- In Relational Algebra 'Table'
4 min read
How to solve Relational Algebra problems for GATE
In this article, Let's discuss common types of questions in relational algebra which are asked in GATE. Before reading this article, you should have an idea about Basic Operators and Extended Operators in relational algebra. Type-1: Given a relational algebra expression, find the result. Suppose you have a relation Order(Prod_Id, Agent_Id, Order_Mo
5 min read
Query Optimization in Relational Algebra
Query: A query is a request for information from a database. Query Plans: A query plan (or query execution plan) is an ordered set of steps used to access data in a SQL relational database management system. Query Optimization: A single query can be executed through different algorithms or re-written in different forms and structures. Hence, the qu
10 min read
Set Theory Operations in Relational Algebra
Relational Algebra in DBMS These Set Theory operations are the standard mathematical operations on set. These operations are Binary operations that are, operated on 2 relations unlike PROJECT, SELECT and RENAME operations. These operations are used to merge 2 sets in various ways. The set operation is mainly categorized into the following: Union op
3 min read
What are the Unary Operations in Relational Algebra?
The unary operations in Relational algebra are selection, projection, and rename. The select, project, and rename operators in relational algebra work on one relation only so they are called unary operators. In this article, we will discuss the unary operations in relational algebra. We will also discuss each unary operator in detail along with exa
4 min read
Query Tree in Relational Algebra
A Query Tree is a data structure used for the internal representation of a query in RDBMS. It is also known as the Query Evaluation/Execution Tree. The leaf nodes of the query tree represent the relations, and the internal nodes are the relational algebra operators like SELECT (σ), JOIN (⋈), etc. The root node gives the output of the query on execu
4 min read
SELECT Operation in Relational Algebra
Prerequisite - Relational Algebra Select operation chooses the subset of tuples from the relation that satisfies the given condition mentioned in the syntax of selection. The selection operation is also known as horizontal partitioning since it partitions the table or relation horizontally. Notation: σ c(R)where 'c' is the selection condition which
2 min read
Extended Operators in Relational Algebra
Basic idea about relational model and basic operators in Relational Algebra: Relational Model Basic Operators in Relational Algebra Extended operators are those operators which can be derived from basic operators. There are mainly three types of extended operators in Relational Algebra: JoinIntersectionDivide The relations used to understand extend
6 min read
Basic Operators in Relational Algebra
Basics of Relational model: Relational Model Relational Algebra is a procedural query language that takes relations as an input and returns relations as an output. There are some basic operators which can be applied in relation to producing the required results which we will discuss one by one. We will use STUDENT_SPORTS, EMPLOYEE, and STUDENT rela
3 min read
Tuple Relational Calculus (TRC) in DBMS
Tuple Relational Calculus (TRC) is a non-procedural query language used in relational database management systems (RDBMS) to retrieve data from tables. TRC is based on the concept of tuples, which are ordered sets of attribute values that represent a single row or record in a database table. TRC is a declarative language, meaning that it specifies
4 min read
Relational Query Language in DBMS
SQL has its own querying methods to interact with the database. But how do these queries work in the database? These queries work similarly to Relational Algebra that we study in mathematics. In the database, we have tables participating in relational Algebra. Relational Database systems are expected to be equipped with a query language that assist
4 min read
Difference between E-R Model and Relational Model in DBMS
In database management systems (DBMS), two key methods are the Relational model and the Entity-Relationship (E-R) model. Each has a specific function in the development and operation of databases. While the Relational model provides the practical structure for organizing and managing data in relational databases, the E-R model concentrates on offer
3 min read
Relational Model in DBMS
E.F. Codd proposed the relational Model to model data in the form of relations or tables. After designing the conceptual model of the Database using ER diagram, we need to convert the conceptual model into a relational model which can be implemented using any RDBMS language like Oracle SQL, MySQL, etc. So we will see what the Relational Model is. T
7 min read
What is Object-Relational Mapping (ORM) in DBMS?
Object-relational mapping (ORM) is a key concept in the field of Database Management Systems (DBMS), addressing the bridge between the object-oriented programming approach and relational databases. ORM is critical in data interaction simplification, code optimization, and smooth blending of applications and databases. The purpose of this article is
7 min read
Domain Relational Calculus in DBMS
Domain Relational Calculus is a non-procedural query language equivalent in power to Tuple Relational Calculus. Domain Relational Calculus provides only the description of the query but it does not provide the methods to solve it. In Domain Relational Calculus, a query is expressed as, { < x1, x2, x3, ..., xn > | P (x1, x2, x3, ..., xn ) } wh
2 min read
Introduction to TimeStamp and Deadlock Prevention Schemes in DBMS
Deadlock occurs when each transaction T in a schedule of two or more transactions waiting for some item locked by some other transaction T' in the set. Thus, both end up in a deadlock situation, waiting for the other to release the lock on the item. Deadlocks are a common problem and we have introduced the problem while solving the Concurrency Cont
7 min read
Introduction of 3-Tier Architecture in DBMS - Set 2
The 3-tier architecture is a commonly used architectural approach in Database Management Systems (DBMSs) for the design and development of applications that work with databases. The 3-tier architecture divides an application’s components into three tiers or layers. Each layer has its own set of responsibilities. DBMS 3-Tier architecture divides the
6 min read
Introduction of DBMS (Database Management System)
A database is a collection of interrelated data that helps in the efficient retrieval, insertion, and deletion of data from the database and organizes the data in the form of tables, views, schemas, reports, etc. For Example, a university database organizes the data about students, faculty, admin staff, etc. which helps in the efficient retrieval,
8 min read
Python | Relational fields in Django models
Prerequisite: Django models Django models represent real-world entities, and it is rarely the case that real-world entities are entirely independent of each other. Hence Django supports relational databases and allows us to establish relations between different models. There are three types of relational fields which Django supports: many-to-one, m
4 min read
Properties of Relational Decomposition
When a relation in the relational model is not appropriate normal form then the decomposition of a relation is required. In a database, breaking down the table into multiple tables termed as decomposition. The properties of a relational decomposition are listed below : Attribute Preservation: Using functional dependencies the algorithms decompose t
3 min read
Violation of constraints in relational database
Here, we will learn about the violations that can occur on a database as a result of any changes made in the relation. There are mainly three operations that have the ability to change the state of relations, these modifications are given below: Insert - To insert new tuples in a relation in the database. Delete - To delete some of the existing rel
3 min read
Difference between Relational model and Document Model
1. Relational Model: Relational model is a model for the management of the database. It is called so because the data is stored in the form of relations i.e., in the form of tables. Every row consists of related data. These row in the table depict a real-world entity. To work with python and the Relational data model we need a prerequisite knowledg
2 min read
Relational Query Evaluation | Set 1
There is a need for conversion of relational query to algebraic expressions. This expression is operated on so that final output is received. The relational algebra operators that are present are Union, Select, Join, Project, etc. These are used to formulate relational query for adequate results. Grouping, partitioning and aggregation are all parts
3 min read
Article Tags :