The Wayback Machine - https://web.archive.org/web/20230512160429/https://www.geeksforgeeks.org/tuple-relational-calculus-trc-in-dbms/
Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App
geeksforgeeks
Browser
Continue

Related Articles

Tuple Relational Calculus (TRC) in DBMS

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

Tuple Relational Calculus (TRC) is a non-procedural query language used in relational database management systems (RDBMS) to retrieve data from tables. TRC is based on the concept of tuples, which are ordered sets of attribute values that represent a single row or record in a database table.

TRC is a declarative language, meaning that it specifies what data is required from the database, rather than how to retrieve it. TRC queries are expressed as logical formulas that describe the desired tuples.

The basic syntax of TRC is as follows:

{ t | P(t) }

where t is a tuple variable and P(t) is a logical formula that describes the conditions that the tuples in the result must satisfy. The curly braces {} are used to indicate that the expression is a set of tuples.

For example, let’s say we have a table called “Employees” with the following attributes:

EmployeeID
Name
Salary
DepartmentID
To retrieve the names of all employees who earn more than $50,000 per year, we can use the following TRC query:

{ t | Employees(t) ∧ t.Salary > 50000 }

In this query, the “Employees(t)” expression specifies that the tuple variable t represents a row in the “Employees” table. The “∧” symbol is the logical AND operator, which is used to combine the condition “t.Salary > 50000” with the table selection.

The result of this query will be a set of tuples, where each tuple contains the Name attribute of an employee who earns more than $50,000 per year.

TRC can also be used to perform more complex queries, such as joins and nested queries, by using additional logical operators and expressions.

While TRC is a powerful query language, it can be more difficult to write and understand than other SQL-based query languages, such as Structured Query Language (SQL). However, it is useful in certain applications, such as in the formal verification of database schemas and in academic research.

Tuple Relational Calculus is a non-procedural query language unlike relational algebra. Tuple Calculus provides only the description of the query but it does not provide the methods to solve it. Thus, it explains what to do but not how to do. 
In Tuple Calculus, a query is expressed as 

{t| P(t)}

where t = resulting tuples, 
P(t) = known as Predicate and these are the conditions that are used to fetch t 

Thus, it generates set of all tuples t, such that Predicate P(t) is true for t. 

P(t) may have various conditions logically combined with OR (∨), AND (∧), NOT(¬). 
It also uses quantifiers: 
∃ t ∈ r (Q(t)) = ”there exists” a tuple in t in relation r such that predicate Q(t) is true. 
∀ t ∈ r (Q(t)) = Q(t) is true “for all” tuples in relation r. 

Example: 
Table-1: Customer 

Customer nameStreetCity
SaurabhA7Patiala
MehakB6Jalandhar
SumitiD9Ludhiana
RiaA5Patiala

Table-2: Branch 

Branch nameBranch city
ABCPatiala
DEFLudhiana
GHIJalandhar

Table-3: Account 

Account numberBranch nameBalance 
1111ABC50000 
1112DEF10000 
1113GHI9000 
1114ABC7000 

Table-4: Loan 

Loan numberBranch nameAmount
L33ABC10000
L35DEF15000
L49GHI9000
L98DEF65000

Table-5: Borrower 

Customer nameLoan number
SaurabhL33
MehakL49
RiaL98

Table-6: Depositor 

Customer nameAccount number
Saurabh1111
Mehak1113
Sumiti1114

Queries-1: Find the loan number, branch, amount of loans of greater than or equal to 10000 amount.  

{t| t ∈ loan  ∧ t[amount]>=10000}

Resulting relation: 

Loan numberBranch nameAmount
L33ABC10000
L35DEF15000
L98DEF65000

In the above query, t[amount] is known as tuple variable. 

Queries-2: Find the loan number for each loan of an amount greater or equal to 10000.  

{t| ∃ s ∈ loan(t[loan number] = s[loan number]  
                   ∧ s[amount]>=10000)}

Resulting relation: 

Loan number
L33
L35
L98

Queries-3: Find the names of all customers who have a loan and an account at the bank.  

{t | ∃ s ∈ borrower( t[customer-name] = s[customer-name])   
     ∧  ∃ u ∈ depositor( t[customer-name] = u[customer-name])}

Resulting relation: 

Customer name
Saurabh
Mehak

Queries-4: Find the names of all customers having a loan at the “ABC” branch.  

{t | ∃ s ∈ borrower(t[customer-name] = s[customer-name]  
   ∧ ∃ u ∈  loan(u[branch-name] = “ABC” ∧ u[loan-number] = s[loan-number]))}

Resulting relation: 

Customer name
Saurabh
My Personal Notes arrow_drop_up
Last Updated : 09 Mar, 2023
Like Article
Save Article
Similar Reads