×

Relational algebra in DBMS

Relational algebra in DBMS

Relational algebra is a procedural query language used to retrieve the data from a database in a different way. It works on the relational model. It performs various operations such as insert, delete, update, and many other operations in the table. As relational algebra is a procedural language, it knows how to retrieve data and which type of data to be retrieved.

Operations in relational algebra:

We can divide the operations in relational algebrainto two categories:

  1. Basic Operation
  2. Derived Operation

Basic Operations:

  • Select (σ)
  • Project (∏)
  • Union (υ)
  • Set Difference(-)
  • Cartesian product (X)
  • Rename (ρ)

Derived Operations:

  • Natural Join
  • Left, right, full outer join
  • Division 
  • Intersection

Let us discuss all one by one:

Select operator

The select operator selects the specific rows (tuples) and shows them in a result set. The selected rows (tuples) will be displayed as the output. These rows (tuple) are selected according to the specified conditions.

The select operator is denoted by the sigma (σ) sign.

Syntax:

σ CONDITION (table_name)

Let's understand this with an example:

Below is a table named STUDENT. First, we will select a specific row where the STUDENT_NAME is "Ram."

Relational algebra in DBMS

Query:

? STUDENT_NAME=”Ram” (STUDENT)

Output:

Relational algebra in DBMS
It is the same as where clause in SQL.

Project Operator:

This operator is used to fetch the specific column which the user wants. The selection of the column is made according to the given condition. This operation deletes the duplicate rows in the table.

 It is denoted by ?(pi).

Syntax:

? CONDITION (table_name)

For example, we have a table STUDENT with three columns, and we are going to fetch only two columns STUDENT_ID and STUDENT_NAME.

Relational algebra in DBMS

Query:

? STUDENT_ID, STUDENT_NAME (STUDENT)

Output:

Relational algebra in DBMS

Union Operator

This operator is used to fetch all rows from the two tables. The ? symbol denotes it. Thus, all the rows (tuple) of the two tables appear once in the union set.

Note: There is no duplicate row present after union operation. If the column is present in both the tables, then only one column will appear containing data of both the tables.

Syntax:

table_name1 ? table_name2

Let’s understand more with the help of an example. We have two tables name STUDENT and BATCH. So we can fetch the data ofthe column “STUDENT_NAME” from both the tables in a single column as below:

Table1:STUDENT

Relational algebra in DBMS

Table2:BATCH

Relational algebra in DBMS

Query:

? STUDENT_NAME (STUDENT) ? ? STUDENT_NAME (BATCH)

Output:

Relational algebra in DBMS

Set Difference

This operation is used to select specific rows. For example, suppose we have two tables (t1 and t2). Now, if we want to select the row which is present in t1, not in t2, this operation can be used. It is denoted by – symbol.

Syntax:

Table_name1 –table_name2

Let’s understand this operation with example taking the same table STUDENT and BATCH present above.

Query:

? STUDENT_NAME (BATCH) - ? STUDENT_NAME (STUDENT)

Output:

Relational algebra in DBMS

Cartesian product (X)

This operation takes place between two tables. For example, let's have two tables, t1 and t2, then the Cartesian product of these two tables is t1Xt2. The product occurs as each row of the first table combines with each row of the second table.

Syntax:

t1 X t2

Let’s take two tables, t2 and t1, for example.

Table t1:

Relational algebra in DBMS

Table t2:

Relational algebra in DBMS

Query:

t1 X t2

Output:

Relational algebra in DBMS

Rename

Rename operation in relational algebra is used to rename the table name or the column name. Rename is denoted by ?. Using rename statement, we can change the table name as well as the column name.

Syntax:

?(new_table_name, old_table_name)

Let's take the above table BATCH in this example. After using this syntax, the new table name will be replaced by the old one. Here we will change the table name to COURSE.

Query:

?(BATCH, COURSE)

The name of the table has been changed from BATCH to COURSE.

Intersection Operation

This operation will select the rows which are present in both tables. It is denoted by ? symbol.

Syntax:

table_name1 ? table_name2

For example: Let ustake table STUDENT and COURSE as an example.

The standard column (with all the data) present in these two tables will be selected and displayed.Here we are going to select STUDENT_ID from both the tables.

Query:

? STUDENT_ID (STUDENT) ? ? STUDENT_ID (COURSE)

Output:

Relational algebra in DBMS

Related Topics

Attributes in DBMS

What is Attribute? An attribute is an element in the database management system that describes the property or certain characteristics of the database entity. It is a crucial element of the...

3 minutes read.

Data Abstraction in DBMS

Introduction Data abstraction is a fundamental concept in database management systems (DBMS). It refers to the process of hiding the details of how data is stored and retrieved from the user,...

3 minutes read.

Why we need Distributed Database Management System

Assuming there is a very strong single machine having properties like: Heaps of memory.Gigantic measure of dependable stockpiling with very quick I/O.Incredible handling rate and processing power (10s, 100s and might...

4 minutes read.

Advantages of RDBMS

The relational database management system collects related data stored in tabular format. The data is stored in rows and columns, where rows usually represent the individual entity of the collected...

6 minutes read.

Inference Rules

Armstrong’s axioms are the complete set of basic inference rules used to infer all the functional dependencies on the relational database. An inference rule is a type of assertion that a user can...

2 minutes read.

DBMS Examples

Introduction to DBMS A database management system (DBMS) is a software application that is designed to manage and organize data stored in a database. It is responsible for storing, retrieving, and...

4 minutes read.

Three Schema Architecture of DBMS

The three schema architecture describes how the data is represented or viewed by the user in the database. This architecture is also known as three-level architecture and is sometimes called...

3 minutes read.

Redundancy in DBMS

Data redundancy is a situation that is created in the database in which the same amount of data is stored in two different places. The different places are found in a...

3 minutes read.

ER Diagram for Banking System in DBMS

Entity Relationship Diagram Entity Relationship Diagrams, or ER Diagrams for short, are diagrams that show the relationships among entity sets that are stored in databases. Alternatively said, ER diagrams assist in...

3 minutes read.

Relational algebra in DBMS

Relational algebra in DBMS Relational algebra is a procedural query language used to retrieve the data from a database in a different way. It works on the relational model. It performs...

3 minutes read.

Anomalies in Database Management System

Anomalies in a database management system (DBMS) are problems that can arise when the database is not designed or implemented correctly. These anomalies can affect the integrity and accuracy of...

3 minutes read.

Relational Integrity Constraints

Relational Integrity Constraints are the set of rules that can be used to maintain the data integrity during an insert, delete and update operations into a table. These constraints are checked in the...

2 minutes read.

Levels of Abstraction in DBMS

Data abstraction is a way to hide unwanted or irrelevant information from the end user in DBMS. It helps in enhancing the security of data, and simplifies database design using...

4 minutes read.

Cardinality in DBMS

Cardinality in DBMS Cardinality is the relationship between two or more entities (table). It shows how all the entities are connected. In DBMS, all the entities and tables are interconnected with...

2 minutes read.

DBMS Schedule

A schedule is a process of combining the multiple transactions into one and executing the operations of these transactions in a predefined order. A schedule can have multiple transactions in it, each transaction...

2 minutes read.

Advantages of Database Management System in DBMS

A database management system (DBMS) is a software tool that provides an interface for managing data stored in a database. Some advantages of using a DBMS include: data integration, data...

3 minutes read.

Conversion of ER Diagram into Relational Model

After designing the Entity-Relationship diagram, you need to convert it into tables in the relational model. Because the relational model can be easily implemented by the Relational DBMS like Oracle, MySQL, etc....

2 minutes read.

Checkpoint in DBMS

A checkpoint in DBMS is used to define a point of the transaction that is in a consistent state and then all the transactions will be in the committed state...

4 minutes read.

ER Model: Entity Relationship Diagram (ERD) with Examples

ER model stands for Entity-Relationship Model. It is a high-level data model diagram which defines the conceptual view of the database. It is a blueprint or design of a database that will...

2 minutes read.

Codds Rule of DBMS

Codd’s Rule of DBMS Database having certain constraints and tables, need not to be a relational database system always. For perfect database management system, there are certain rules for the database,...

3 minutes read.