0% found this document useful (0 votes)
4 views11 pages

Tuple Relational Calc

Uploaded by

Kashish Bhalla
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views11 pages

Tuple Relational Calc

Uploaded by

Kashish Bhalla
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Tuple Relational Calculus (TRC) in

DBMS
Tuple Relational Calculus (TRC) in DBMS

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.
Syntax:

{ 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.
Example

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

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

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


Department ID

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.
Domain Relational Calculus (DRC)

Domain Relational Calculus is similar to Tuple Relational Calculus, where it makes a list
of the attributes that are to be chosen from the relations as per the conditions.

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

where a1,a2,…an are the attributes of the relation and P is the


condition.
Tuple Relational Calculus Examples

Table Customer Table Branch Table Account


Customer Branch name Branch City Account number Branch name Balance
Street City
name
ABC Patiala 1111 ABC 50000
Saurabh A7 Patiala
DEF Ludhiana 1112 DEF 10000
Mehak B6 Jalandhar
GHI Jalandhar 1113 GHI 9000
Sumiti D9 Ludhiana
1114 ABC 7000
Ria A5 Patiala
Table Loan

Loan number Branch name Amount

L33 ABC 10000

L35 DEF 15000

L49 GHI 9000

L98 DEF 65000


Table Borrower Table Depositor

Customer name Loan number Customer name Account number

Saurabh L33 Saurabh 1111

Mehak L49 Mehak 1113

Ria L98 Suniti 1114


Resulting relation:
Example 1: Find the loan number, branch, and amount of
loans greater than or equal to 10000 amount.
Loan number Branch name Amount

L33 ABC 10000

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

L98 DEF 65000


In the above query, t[amount] is known as a tuple
variable.
Example 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:
The ∃ (there exists) symbol is used in math to express the existence of a variable.
Loan number

L33

L35

L98
Questions

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

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

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


depositor( t[customer-name] = u[customer-name])}

Example 4 {t | ∃ s ∈ borrower(t[customer-name] = s[customer-name] ∧ ∃ u ∈


loan(u[branch-name] = “ABC” ∧ u[loan-number] = s[loan-number]))}
Thank you

Find out more at the PowerPoint Getting Started Center


(Click the arrow when in Slide Show
mode)

You might also like