Updated April 1, 2023
Introduction to Relational Calculus in DBMS
Relational calculus in RDBM is referring to the non-procedural query language that emphasizes on the concept of what to for the data management rather how to do those. The relational calculus provides descriptive information about the queries to achieve the required result by using mathematical predicates calculus notations. It is an integral part of the relational data model. The relational calculus in DBMS uses specific terms such as tuple and domain to describe the queries. Some of the other related common terminologies for relational calculus are variables, constant, Comparison operators, logical connectives, and quantifiers. It creates the expressions that are also known as formulas with unbound formal variables.
Types of Relational Calculus in DBMS
In this section, we will discuss the types of relational calculus in DBMS based on the terms and process of the mathematical description of queries functionalities. Tuple and domain are the major components of relational calculus. A result tuple is an assignment of constants to these
Variables that make the formula evaluate to be true. There are two types of relational calculus available in DBMS
- Tuple relational calculus (TRC)
- Domain relational calculus (DRC)
Both the types of relational calculus are semantically similar for operating in DBMS data retrieval definitions. We will discuss each type of relational calculus with some database table examples to represent the syntax and its uses.
TRC
Tuple relational calculus works on filtering the tuples based on the specified conditions.TRC is the variable range over the tuples and is a type of simple subset of the first-order logic.TRC considers tuples as equal status as variables, and field referencing can be used to select the tuple parts. It is represented using letter ‘T’ and conditions with the pipe symbol and enclosing curly braces.
Syntax of TRC:
{T | Conditions)
The TRC syntax supports to denote the Table names or relation names, defining the tuple variables, and the column names. It uses the ‘.’ operator symbol to specify the column names with the table name.
TRC specifies the relation names with the Tuple variable name such as ’T’. Syntax of Relation definition in TRC:
Relation(T)
For example, if the Product is the relation name, it can be denoted as Product(T). Similarly, TRC has the provision to specify the conditions. The condition is applicable for a particular attribute or the column.
For instance, if the data need to be represented for the particular product id of value 10, it can be denoted as T.product_id=10, where T is the tuple variable that represents the row of the table.
Let us assume the Product table in the database as follows:
Product_id | Product Category | Product Name | Product Unit Price |
8 | New | TV Unit 1 | $100 |
10 | New | TV Unit 2 | $120 |
12 | Existing | TV Cabinet | $77 |
Now to represent the relational calculus to return the product name that has the product id value as 10 from the product table, it can be denoted as with the tuple variable T.
T.Product Name | Product(T) AND T.Product_id = 10
This relational calculus predicate describes what to do for getting the resultant tuple from the database. The result of the tuple relational calculus for the Product table will be:
Product_id | Product Name |
10 | TV Unit 2 |
DRC
The domain regional calculus works based on the filtering of the domain and the related attributes.DRC is the variable range over the domain elements or the filed values. It is a type of simple subset of first-order logic. It is domain-dependent compared to TRC is tuple dependent. In DRC the formal variables are explicit for the relational calculus representations. The domain attributes in DRC can be represented as C1, C2,…, Cn and the condition related to the attributes can be denoted as the formula defining the condition for fetching the F(C1, C2, …Cn )
Syntax of DRC in DBMS
{c1, c2,...,cn| F(c1, c2,... ,cn)}
Let us assume the same Product table in the database as follows:
Product_id | Product Category | Product Name | Product Unit Price |
8 | New | TV Unit 1 | $100 |
10 | New | TV Unit 2 | $120 |
12 | Existing | TV Cabinet | $77 |
DRC for the product name attribute from the Product table needs where the product id is 10, It will be demoted as:
{< Product Name, Product_id> | ∈ Product ∧ Product_id> 10}
The result of the domain relational calculus for the Product table will be
Product_id | Product Name |
10 | TV Unit 2 |
Some of the commonly used logical operator notations for DRC are ∧ for AND,∨ for OR, and ┓ for NOT. imilarly, the mathematical symbol ∈ refers to the relation “is an element of” or known as the set membership.
Conclusion
The relational calculus is the schematic description of the queries that provide the structured approach for what the functionalities should be to retrieve and process the data in the relational database. It specifies the scenarios of what to do using the queries that help to implement the syntactical form of the queries in the databases.
Recommended Articles
We hope that this EDUCBA information on “Relational Calculus in DBMS” was beneficial to you. You can view EDUCBA’s recommended articles for more information.