Related Articles

# Tuple Relational Calculus (TRC) in DBMS

• Difficulty Level : Medium
• Last Updated : 20 Aug, 2019

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 tupple 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

Attention reader! Don’t stop learning now.  Practice GATE exam well before the actual exam with the subject-wise and overall quizzes available in GATE Test Series Course.

Learn all GATE CS concepts with Free Live Classes on our youtube channel.

My Personal Notes arrow_drop_up