Tuple Relational Calculus in DBMS [GATE Notes]

By Mukul Yadav|Updated : April 16th, 2023

Tuple Relational Calculus (TRC) and Domain Relational Calculus (DRC) are both formal languages used to specify queries on a relational database. They are non-procedural languages that operate on a set of tuples (rows) in one or more relations (tables) and return a set of tuples that satisfy a given condition. The main difference between Tuple Relational Calculus and Domain Relational Calculus is the way they express queries. Tuple Relational Calculus expresses queries in terms of logical formulas using variables to refer to tuples and conditions to restrict the result set, while DRC expresses queries in terms of domain variables and quantifiers, which are used to specify constraints on the tuples that should be returned.

Tuple Relational Calculus is based on the concept of first-order logic and is similar to predicate calculus, whereas Domain Relational Calculus is based on the concept of second-order logic and is similar to set-builder notation in mathematics. Let us see the important concepts related to Tuple Relational Calculus and prepare it well for the upcoming GATE CSE exam.

Tuple Relational Calculus in DBMS

Tuple Relational Calculus (TRC) is a formal language used to specify queries on a relational database. It is a non-procedural language that operates on a set of tuples (rows) in one or more relations (tables) and returns a set of tuples that satisfy a given condition. TRC expresses queries in terms of logical formulas, using variables to refer to tuples and conditions to restrict the result set. The variables can be constrained using selection and projection operators, and the conditions can be combined using logical operators such as AND, OR, and NOT.

• A tuple relational calculus is a non-procedural query language that specifies to select 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.
• It uses first-order Logic to generate the result.
• All the conditions used in the tuple expression are called a well-formed formula – WFF.
• All the conditions in the expression are combined by using logical operators like AND, OR, and NOT, and quantifiers like ‘For All’ (?) or ‘there exists’ (?).
• If the tuple variables are all bound variables in a WFF is called a closed WFF.
• In an open WFF, we will have at least one free variable.

Tuple Relational Query

A tuple relational query (TRQ) is a query language used to retrieve data from a relational database. It operates on a set of tuples (rows) in one or more relations (tables) and returns a set of tuples that meet the specified criteria.

TRQ is a declarative language, meaning that the user specifies what data they want and the database management system (DBMS) determines how to retrieve it. TRQ has a similar syntax to SQL (Structured Query Language), but the main difference is that TRQ operates on individual tuples rather than on sets of tuples.

• {t | P (t)} or {t | condition (t)} -- this is also known as expression of relational calculus

•  Where t is the resulting tuples, P(t) is the condition used to fetch t.

• P(t) is the first-order predicate logic to set the condition, and t is the tuple variable.

Tuple Variables

There are basically two types of tuple variables

• Free Variables: Any tuple variable without any ‘For All’ or ‘there exists’ condition is called Free Variable in C. In a simple manner, we can say that if the tuple variable is not bounded to quantifiers, then it is said to be a free variable.

Example:{t | EMPLOYEE (t) AND t.DEPT_ID = 10} – this selects all the tuples of employee names who work for Department 10.

• Bounded Variables: Any tuple variable with the ‘For All’ or ‘there exists’ condition is called Bounded Variable. In a simple manner, we can say that if the tuple variable is bounded to quantifiers, then it is said to be a bounded variable.

Example: {t | EMPLOYEE (t) and t.SALARY>10000}  - implies that it selects the tuples from EMPLOYEE relation such that resulting employee tuples will have salaries greater than 10000. This is an example of selecting a range of values.

Unsafe Query

A TRC Query with an infinite set of tuples in the result is said to be an unsafe query. the reason for a query being unsafe is basically the use of a universal tuple variable. The domain of the universal tuple variable is not restricted to the relation for which it is getting used.

Example:{t| t ∉ Student}- this query will result in all the tuples which are not part of the student table which are infinite. hence the query is unsafe.

Domain Relational Calculus(DRC)

As compared to tuple relational calculus, domain relational calculus makes use of the list of attributes that needs to be selected from the relation based on the condition. Domain relational calculus is the same as tuple relational calculus it only differs in the way of selecting the attributes instead of selecting whole tuples. It is denoted as below:

{< a1, a2, a3, … an > | P(a1, a2, a3, … an)}

Where a1, a2, a3, … an are attributes of the relation and P is the condition.

For e.g.: Select the EMP_NAME and EMP_ID of employees who work for Department 12

{<EMP_ID, EMP_NAME> | <EMP_ID, EMP_NAME> ? EMPLOYEE Λ DEPT_ID = 12}

Other concepts of Tuple Relational Calculus like a free variable, bound variable, WFF, etc. remain the same in Domain Relational Calculus too. The only difference is Domain Relational Calculus is based on attributes of the relation.

Tuple Relational Calculus Examples

Tuple Relational Calculus (TRC) is a query language that is used to retrieve data from a relational database by specifying conditions that the desired tuples must satisfy. Here are a few examples of Tuple Relational Calculus:

• Retrieve all the employees who work in the "Sales" department.: {t | Employee(t) ∧ t.department = "Sales"}
• Retrieve the names of all the employees who earn more than \$50,000.: {t.name | Employee(t) ∧ t.salary > 50000}
• Retrieve the names of all the employees who work in the "Sales" department and earn more than \$50,000.: {t.name | Employee(t) ∧ t.department = "Sales" ∧ t.salary > 50000}
 Other Important GATE Topics 2's Complement Data Hazard Floating Point Representation Asynchronous Counter User-defined Data Types in C Full Subtractor

write a comment

FAQs on Tuple Relational Calculus

• The purpose of TRC is to specify queries on a relational database. It allows users to retrieve data from a database by expressing queries in a formal language that can be understood by the database management system.

• The main difference between TRC and DRC is the way they express queries. TRC uses logical formulas and variables to refer to tuples, while DRC uses domain variables and quantifiers to specify constraints on the tuples that should be returned.

• TRC and DRC are used to specify queries in relational database management systems (RDBMS). They allow users to retrieve data from a database by expressing queries in a formal language that can be understood by the RDBMS.

• The main advantage of using TRC and DRC is that they provide a formal, precise way of expressing queries on a relational database. This allows queries to be written in a way that is both concise and easy to understand, and it can also help to ensure that queries are correct and efficient.

• Some common operators used in TRC and DRC include selection, projection, union, intersection, and difference. These operators are used to retrieve data from one or more tables based on specified conditions.

GATE & PSU CS

Computer ScienceGATEGATE CSENIELITOther ExamsQuick LinksMock Test