Tuple & Domain Relational Calculus
Tuple & Domain Relational Calculus
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
Table-4: Loan
Loan number Branch name Amount
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
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.
Table-2: Loan
Loan number Branch name Amount
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:
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:
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 :
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 :
In TRS, the variables represent the In DRS, the variables represent the value
tuples from specified relation. drawn from specified domain.
In this filtering variable uses tuple of In this filtering is done based on the
relation. domain of attributes.
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 }