0% found this document useful (0 votes)
23 views17 pages

DBMS 14

Uploaded by

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

DBMS 14

Uploaded by

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

Relational Calculus

KALINGA INSTITUTE OF INDUSTRIAL


TECHNOLOGY

School Of Computer
Engineering

Dr. Pradeep Kumar Mallick


Associate Professor [II]
School of Computer Engineering,
Kalinga Institute of Industrial Technology (KIIT),
Deemed to be University,Odisha

4 Credit Lecture Note 14


Chapter Contents
2

 Relational Calculus
 Tuple Relational Calculus
 Safe Expressions
 Queries

 Domain Relational Calculus


 Queries
Relational Calculus
3

 Relational calculus is non-procedural.


 In relational calculus, a query is solved by defining a solution relation in a
single step.
 Relational calculus is mainly based on the well-known propositional calculus,
which is a method of calculating with sentences or declarations.
 Various types of relational calculus are:
 Tuple Relational Calculus (TRC)

 Domain Relational Calculus (DRC)


Tuple Relational Calculus
4
 A tuple variable is a variable that takes on tuples of a particular relation schema
as values.
 A tuple relational calculus query has the form: {T/ P(T)}
 The result of this query is the set of all tuples t for which the formula P(T)
evaluates to TRUE with T = t

Sailors (sid, sname, rating, age)

Query: Find all the sailors with a rating above 4


{S/S ∈ Sailors ∧ S.rating > 4}
Tuple Relational Calculus
5
 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(¬).
Tuple Relational Calculus
6
 Let Rel → be a relation name, R, S → be the tuple variables, a → an attribute
of R, b → an attribute of S, op → operator in the set {<, ≤ , >, ≥ , =, ^=}. An
Atomic formula is one of the following:
 R ∈ Rel
 R.a op S.b
 R.a op Constant or Constant op R.a
 To represent the join and division of relational algebra by relational calculus,
we need quantifiers such as: existential for join and universal for division.
 A quantifier quantifies or indicates the quantity of something.
 The existential quantifier (∃) states that at least one instance of a particular type
of thing exist Similarly, the universal quantifier ( ∀) states that some condition
applies to all or to every row of some type.
 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 T as a variable, then ∃ T(p) and ∀ T(p) are also
formulae.
Tuple Relational Calculus
7
 The quantifiers ∃ and ∀ are said to bind the tuple variable R; 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.
 In most of the queries, the output is shown by using the free variables.
 Safe Expressions: Whenever we use universal quantifiers or existential
quantifiers in a calculus expression, we must make sure that the resulting
expression makes sense.
 A safe expression in relational calculus is one that is guaranteed to yield a
finite number of tuples as its result; otherwise, the expression is called unsafe.
 That means, an expression is said to be safe if all values in its result are from
the domain of the expression.
Link:
https://www.bing.com/videos/search?
q=tuple+relational+calculus+in+dbms&&view=detail&mid=D89B294872
B496B4033CD89B294872B496B4033C&&FORM=VRDGAR&ru=
%2Fvideos%2Fsearch%3Fq%3Dtuple%2Brelational%2Bcalculus%2Bin
%2Bdbms%26FORM%3DHDRSC3
Tuple Relational Calculus
8

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

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy