0% found this document useful (0 votes)
222 views7 pages

Tuple & Domain Relational Calculus

Tuple Relational Calculus (TRC) is a non-procedural query language that describes what to retrieve from a database without specifying how to do it, using predicates and quantifiers. Domain Relational Calculus (DRC) is similar but focuses on selecting attributes rather than entire tuples. The document also outlines the differences between TRC and DRC, providing examples of queries for both types of calculus.

Uploaded by

dvarshitha04
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)
222 views7 pages

Tuple & Domain Relational Calculus

Tuple Relational Calculus (TRC) is a non-procedural query language that describes what to retrieve from a database without specifying how to do it, using predicates and quantifiers. Domain Relational Calculus (DRC) is similar but focuses on selecting attributes rather than entire tuples. The document also outlines the differences between TRC and DRC, providing examples of queries for both types of calculus.

Uploaded by

dvarshitha04
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/ 7

Tuple Relational Calculus (TRC) in DBMS

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 name Street City

Saurabh A7 Patiala

Mehak B6 Jalandhar

Sumiti D9 Ludhiana

Ria A5 Patiala

Table-2: Branch
Branch name Branch city

ABC Patiala

DEF Ludhiana

GHI Jalandhar
Table-3: Account
Account number Branch name Balance

1111 ABC 50000

1112 DEF 10000

1113 GHI 9000

1114 ABC 7000

Table-4: Loan
Loan number Branch name Amount

L33 ABC 10000

L35 DEF 15000

L49 GHI 9000

L98 DEF 65000

Table-5: Borrower
Customer name Loan number

Saurabh L33

Mehak L49

Ria L98

Table-6: Depositor
Customer name Account number

Saurabh 1111

Mehak 1113

Sumiti 1114

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 number Branch name Amount

L33 ABC 10000

L35 DEF 15000

L98 DEF 65000

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
Domain Relational Calculus in DBMS
Domain Relational Calculus is a non-procedural query language equivalent in power to
Tuple Relational Calculus. Domain Relational Calculus provides only the description of the
query but it does not provide the methods to solve it. In Domain Relational Calculus, a
query is expressed as,
{ < x1, x2, x3, ..., xn > | P (x1, x2, x3, ..., xn ) }
where, < x1, x2, x3, …, xn > represents resulting domains variables and P (x 1, x2, x3, …, xn )
represents the condition or formula equivalent to the Predicate calculus.

Predicate Calculus Formula:


1. Set of all comparison operators
2. Set of connectives like and, or, not
3. Set of quantifiers
Example:
Table-1: Customer
Customer name Street City

Debomit Kadamtala Alipurduar

Sayantan Udaypur Balurghat

Soumya Nutanchati Bankura

Ritu Juhu Mumbai

Table-2: Loan
Loan number Branch name Amount

L01 Main 200

L03 Main 150

L10 Sub 90

L08 Main 60

Table-3: Borrower
Customer name Loan number

Ritu L01

Debomit L08
Customer name Loan number

Soumya L03

Query-1: Find the loan number, branch, amount of loans of greater than or equal to 100
amount.
{≺l, b, a≻ | ≺l, b, a≻ ∈ loan ∧ (a ≥ 100)}
Resulting relation:

Loan number Branch name Amount

L01 Main 200

L03 Main 150

Query-2: Find the loan number for each loan of an amount greater or equal to 150.
{≺l≻ | ∃ b, a (≺l, b, a≻ ∈ loan ∧ (a ≥ 150)}
Resulting relation:

Loan number

L01

L03

Query-3: Find the names of all customers having a loan at the “Main” branch and find the
loan amount .
{≺c, a≻ | ∃ l (≺c, l≻ ∈ borrower ∧ ∃ b (≺l, b, a≻ ∈ loan ∧ (b = “Main”)))}
Resulting relation:

Customer Name Amount

Ritu 200

Debomit 60

Soumya 150

Note:
The domain variables those will be in resulting relation must appear before | within ≺ and
≻ and all the domain variables must appear in which order they are in original relation or
table.
Difference between Tuple Relational Calculus
(TRC) and Domain Relational Calculus (DRC)
1. Tuple Relational Calculus (TRC) :
A tuple relational calculus is a non procedural query language which specifies to select the
tuples in a relation. It can select the tuples with range of values or tuples for certain attribute
values etc. The resulting relation can have one or more tuples.

Notation :
{T | P (T)} or {T | Condition (T)}
-where T is resulting tuples and P(T) is a condition used to fetch T.
Example :

{T | EMPLOYEE (T) AND T.DEPT_ID = 10}


This select all the tuples of employee name who work for Department 10.
2. Domain Relational Calculus (DRC) :
A domain relational calculus uses list of attribute to be selected from the relation based on the
condition. It is same as TRC, but differs by selecting the attributes rather than selecting whole
tuples.

Notation :
{ a1, a2, a3, ..., an | P (a1, a2, a3, ..., an) }
-Where a1, a2, a3, … an are attributes of the relation and P is the condition.
Example :

{ | < EMPLOYEE > DEPT_ID = 10 }


select EMP_ID and EMP_NAME of employees who work for department 10.
Difference between Tuple Relational Calculus (TRC) and Domain Relational Calculus
(DRC) :

Tuple Relational Calculus (TRC) Domain Relational Calculus (DRC)

In TRS, the variables represent the In DRS, the variables represent the value
tuples from specified relation. drawn from specified domain.

A tuple is a single element of relation. In A domain is equivalent to column data


database term, it is a row. type and any constraints on value of data.

In this filtering variable uses tuple of In this filtering is done based on the
relation. domain of attributes.

Query cannot be expressed using a Query can be expressed using a


membership condition. membership condition.

The QUEL or Query Language is a The QBE or Query-By-Example is query


query language related to it, language related to it.
Tuple Relational Calculus (TRC) Domain Relational Calculus (DRC)

It reflects traditional pre-relational file It is more similar to logic as a modelling


structures. language.

Notation : Notation :
{T | P (T)} or {T | Condition (T)} { a1, a2, a3, …, an | P (a1, a2, a3, …, an)}

Example :
{T | EMPLOYEE (T) AND T.DEPT_ID Example :
= 10} { | < EMPLOYEE > DEPT_ID = 10 }

You might also like