×

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

ER Diagram for Student Management System in DBMS

Entity Relationship diagrams 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...

6 minutes read.

What is Non-Relational Database

Databases can be sorted as either relational or non-relational. Non-relational data sets are now and again alluded to as "NoSQL," which represents Not Only SQL. The principal difference between these...

4 minutes read.

Disavantages of RDBMS

RDBMS offers many features when handling the data, but it also has certain limitations that can be overcome by choosing an alternative data model. The limitations of the Relational Data...

3 minutes read.

Defference between Database and Data Warehouse

Database A database is a collection of related information is called a database. It has some elements that can be mapped to real-world objects. It is designed in such a manner...

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.

Schedule in DBMS

Schedule A sequence of statements that specify the sequential order in which the statements of concurrent transactions are executed. The transaction will get committed when it executes the instructions successfully without any...

4 minutes read.

Domain in DBMS

Constraints: Constraints in DBMS are a set of guidelines that guarantee that authorized users who modify the database do not alter the consistency of the data. Constraints are expressed in DDL...

3 minutes read.

Red-Black Tree Properties in DBMS

What is a Red-Black Tree? A red-black tree is a kind of self-balancing binary search tree. The extra bit that each node keeps denoting "color"-either "red" or "black"-is needed to keep...

3 minutes read.

Normalization in DBMS: 1NF, 2NF, 3NF, BCNF & 4NF with Examples

Normalization is a technique of organizing the data in the database. It is a systematic approach which is used to remove or reduce data redundancy in the tables and remove the...

7 minutes read.

Deadlock in DBMS

Deadlock in DBMS A deadlock is an unwanted condition in which two or more transaction are waiting indefinitely for one another to give up locks. It is said to be one of the...

3 minutes read.

Difference between Dropbox and Amazon Drive

What is Dropbox? It is a file organising company that is owned by the American Company Dropbox Inc. Itsheadquarters is situated in San Francisco, California, U.S. Dropbox offers personal cloud, client...

3 minutes read.

B+ (Plus) Tree in DBMS

What is a B+ tree? The B+ tree is known as a balanced binary search tree. in this tree, we can store the data in the form of nodes. B+ tree...

9 minutes read.

Disadvantages of DBMS

Disadvantages of DBMS With the vast list of advantages, there are some following disadvantages or limitations of the database management system. 1. High Cost The high cost of software and hardware is the...

2 minutes read.

Difference between DBMS and RDBMS

Database Management System A DBMS is system software which is used to store and manage the data in the database. It was introduced in 1960 for storing the data or information. This system allows...

3 minutes read.

Primary Key in DBMS

Primary Key in DBMS: A primary key is the minimal set of columns in the database table, which uniquely identifies each row or tuple in that table. Any table in...

2 minutes read.

Aggregate Functions in DBMS

Aggregate Functions in DBMS: Aggregate functions are those functions in the DBMS which takes the values of multiple rows of a single column and then form a single value by...

2 minutes read.

Conflict Serializability in DBMS

Conflict Serializability A schedule is said to be conflict serializable if it can transform into a serial schedule after swapping of non-conflicting operations. It is a type of serializability that can be used...

3 minutes read.

Founder of DBMS

The first database management system was built to automate the business of the General Electric Company. It was built by a small group of programmers. The Integrated Data Store IDS...

4 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.

What is Advanced Database Management System

Before diving into the Advance Database management system, we need to learn about the database management system and its usage. Database management system Database Management System or DBMS in short implies the...

3 minutes read.