Relational Calculus in DBMS

Relational Calculus

In DBMS, Relational Calculus is a unique technique to query creation. Relational calculus in DBMS is a non-procedural language in which the user is concerned with the details of achieving the desired results.

The name "relational" in relational calculus relates to the fact that it is built on the relational data model, which serves as the foundation for relational database management systems (RDBMS). While the term "calculus" refers to a formal system of reasoning for expressing queries across relational databases.

Relational Calculus in DBMS

Example of relational calculus in DBMS 

Select the tuples from EMPLOYEE relation with DEPARTMENT =' Networking '

In the above example, this is the relational calculus phrase for selecting tuples from the EMPLOYEE relation when DEPARTMENT='NETWORKING'.


Types of Relational Calculus in DBMS 

There are mainly two types of relational calculus :

  • Tuple Relational Calculus (TRC)
  • Domain Relational Calculus (DRC)

1. Tuple Relational Calculus in DBMS 

Tuple Relational Calculus in DBMS is based on the idea of selecting tuples (rows) from a relation (table) that meet specific criteria. Tuple Relational Calculus use variables to represent tuples and logical predicates to indicate the requirements that must be met before the tuples are selected. The generated expression is a formula that describes a collection of tuples that satisfy the given conditions.

The general syntax for Tuple Relational Calculus is :

{ t | P ( t ) } or {t | Condition ( t ) }

The resulting tuples are denoted by t in the above syntax, and P(t) is the condition that produced them. Let's look at an example for better understanding the tuple relational calculus in databases.


Example of Tuple Relational Calculus in DBMS :

Now we will try to apply the Tuple Relational Calculus expression to the database table Employee.

Employee ID Employee Name Department
101 Nainita Computer
102 Sahil Finance
103 Deepak Computer
104 Niku Account
105 Gautam Computer

Query :

{ t \ | t ε Employee ^ t. Department = 'Computer ' } or TRC Query : { t \ | Employee (t) ^ t[ Department ] = 'Computer ' }

Output : 

Employee ID Employee Name Department
101 Nainita Computer
103 Deepak Computer
105 Gautam Computer

The preceding query will pick tuples from the Employee table where the Department is 'Computer'. In the output, we can see that three tuples are returned from the table Employee, indicating the department, the employee works in.


2. Domain Relational Calculus in DBMS :

Domain Relational Calculus in DBMS is based on the concept of grabbing values from a relation (table) that fulfill specific criteria. Domain Relational Calculus use variables to represent individual values and logical predicates to express the requirements that must be met for the values to be decided. The resulting expression is a formula that describes a set of values that satisfy the given conditions.


Syntax 

{  | p (x1, x2, x3, ...., xn ) }

The domain variables, represented by <x1,x2,x3,x4,…,xn>, are used to retrieve column values in the given syntax. P(x1,x2,x3,x4,…,xn) refers to a predicate condition or expression. 

Let us use an example to better grasp the tuple relational calculus in database management systems.


Example 

Now, we'll try to apply the Domain Relational Calculus expression to the database table Employee.

Employee ID Employee Name Department
101 Nainita Computer
102 Sahil Finance
103 Deepak Computer
104 Niku Account
105 Gautam Computer

Query 

{ \ | ε Employee ^ x3 = ' Computer ' }

Output 

Employee ID

Employee Name

Department

101

Nainita

Computer

103

Deepak

Computer

105

Gautam

Computer


The predicate condition requires that the first two domain variables, x1 and x2, be present while each row matches the condition, and that the third domain variable, x3, be equal to "Computer" in the query above. x1, x2, and x3 (ordered) denote the attribute or column that we require in the result.


Conclusion 

Finally, this tutorial will help you learn relational calculus in DBMS. In addition, you will also be introduced the many forms of relational calculus in DBMS using appropriate examples.

Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.

Top Post Ad

Below Post Ad