DBMS 14
DBMS 14
School Of Computer
Engineering
Relational Calculus
Tuple Relational Calculus
Safe Expressions
Queries
Customer(CUSTOMER NAME,STREET,CITY)
Branch(BRANCH_NAME,BRANCH CITY)
Account(ACCOUNT_NUMBER, BRANCH_NAME, BALANCE)
Loan(LOAN NUMBER., BRANCH NAME, AMOUNT)
Borrower(CUSTOMER NAME,LOAN NUMBER)
Depositor(CUSTOMER NAME,ACCOUNT NUMBER)
Q.1 Find the loan number, branch, amount of loans of greater than or equal
to 10000 amount.
Ans: {t| t ∈ loan ∧ t[amount]>=10000}
Q.2 Find the loan number for each loan of an amount greater or equal to
10000.
Ans: {t| ∃ s ∈ loan(t[loan number] = s[loan number] ∧ s[amount]>=10000)}
Tuple Relational Calculus
9
Q-3: Find the names of all customers who have a loan and an account at
the bank.
Ans: {t | ∃ s ∈ borrower( t[customer-name] = s[customer-name])
∧ ∃ u ∈ depositor( t[customer-name] = u[customer-name])}
Q.4 Find the names of all customers having a loan at the “ABC” branch.
Ans: {t | ∃ s ∈ borrower(t[customer-name] = s[customer-name]
∧ ∃ u ∈ loan(u[branch-name] = “ABC” ∧ u[loan-number] = s[loan-number]))}
( Source: https://www.geeksforgeeks.org/tuple-relational-calculus-trc-in-dbms/ )
Queries
10
Queries…
11
Queries…
12
link: https://www.bing.com/videos/search?
q=tuple+relational+calculus+in+dbms&&view=detail&mid=50820
852B028DB238E2050820852B028DB238E20&&FORM=VRDG
AR&ru=%2Fvideos%2Fsearch%3Fq%3Dtuple%2Brelational
%2Bcalculus%2Bin%2Bdbms%26FORM%3DHDRSC3
Domain Relational Calculus (DRC)
13
In tuple relational calculus, the variables range over the tuples whereas in
domain relational calculus, the variables range over the domains.
Let Rel → be a relation name, X, Y → be the domain variables, op → an
operator in the set {<, ≤, >, ≥, =, ^=}. An Atomic formula in domain relational
calculus is one of the following:
<x1, x2, ... xn > ∈ Rel
X op Y
X op Constant or Constant op X
A formula is recursively defined by using the following rules:
Any atomic formula
If p and q are formulae, then ¬p, p ∧ q, p ∨ q, or p ⇒ q are also formulae
If p is a formula that contains X as a domain variable, then ∃X(p) and ∀
X(p) are also formulae
The quantifiers ∃ & ∀ are said to bind the domain variable X. Whereas a
variable is said to be free in a formula if the formula does not contain an
occurrence of a quantifier that binds it.
Domain Relational Calculus (DRC)
14
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 (x1,
x2, x3, …, xn ) represents the condition or formula equivalent to the Predicate
calculus.
Predicate Calculus Formula:
Set of all comparison operators
1. Set of connectives like and, or, not
2. Set of quantifiers
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)}
(https://www.geeksforgeeks.org/domain-relational-calculus-in-dbms/)
Queries
15
Queries…
16
17