0% found this document useful (0 votes)
12 views26 pages

10.RC_TRC_DRC

The document compares Relational Algebra and Relational Calculus, highlighting that Relational Algebra is procedural while Relational Calculus is non-procedural. It explains the two variants of Relational Calculus: Tuple Relational Calculus (TRC) and Domain Relational Calculus (DRC), and their similarities in expressive power. The document also provides examples and definitions related to both concepts, emphasizing their roles in database query formulation.

Uploaded by

ishaan0643.be21
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)
12 views26 pages

10.RC_TRC_DRC

The document compares Relational Algebra and Relational Calculus, highlighting that Relational Algebra is procedural while Relational Calculus is non-procedural. It explains the two variants of Relational Calculus: Tuple Relational Calculus (TRC) and Domain Relational Calculus (DRC), and their similarities in expressive power. The document also provides examples and definitions related to both concepts, emphasizing their roles in database query formulation.

Uploaded by

ishaan0643.be21
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/ 26

Database Management System (CS-116) Class

On

Database Management System

Department of Computer Science and Engineering,


Chitkara University, Punjab

DBMS-CS116
Comparison of Relational Algebra &
Relational Calculus

Relational Algebra Relational Calculus


It is a procedural method of solving the queries. It is non-procedural method of solving the
queries.

The solution to the database access problem The solution to the database access problem
using a relational algebra is obtained by stating using a relational calculus is obtained simply
what is required and what are the steps to by stating what is required and letting the
obtain that information. system find the answer.
It is used as a vehicle for implementation of Relational calculus queries are converted into
Relational Calculus. equivalent relational algebra format by using
Codd’s reduction algorithm and then it is
implemented with the help of relational algebra
operators.
Relational algebra operators are used as a A language is said to be complete if it is at least
yardstick for measuring the expressive power as powerful as the calculus.
of any given language.

Database Management System (DBMS)


Mar 17 2
Relational Calculus

• There are two versions of the relational calculus:


• Tuple relational calculus (TRC)
• Domain relational calculus (DRC)
• The calculus is non-procedural (‘declarative’) compared to the relational
algebra
• Calculus has variables, constants, comparison ops, logical connectives and
quantifiers.
• TRC: Variables range over (i.e., get bound to) tuples.
• DRC: Variables range over domain elements (= field values).
• Both TRC and DRC are simple subsets of first-order logic.

• Expressions in the calculus are called formulas.


• An answer tuple is essentially an assignment of constants to variables that
make the formula evaluate to true.
Relational Calculus
• Relational Algebra is a PROCEDURAL LANGUAGE
 we must explicitly provide a sequence of operations to generate a desired
output result

• Relational Calculus is a DECLARATIVE LANGUAGE


 we specify what to retrieve, not how to retrieve it
 Final result
 {t | P(t)}: expressed (logically combined ) (OR(v) and, not)
 Atomic function (one variable) one condition

• Variable predicate
What is Relational Calculus?

• It is a formal language based upon predicate calculus


• It allows you to express the set of tuples you want from a database using a
formula
• Expressions in the calculus are called formula
• An answer tuple is essentially an assignment
of constants to variables that make the formula evaluate to true.
Declarative ~ Non-Procedural

Two variants of relational calculus are


• TUPLE Relational Calculus
• Domain Relational Calculus
• Calculus has variables, constants, comparison ops, logical connectives
and quantifiers.
• TRC: Variables range over (i.e., get bound to) tuples.
• DRC: Variables range over domain elements (= field values)
Relational Calculus

• If a retrieval can be specified in the relational calculus, it can be specified


in the relational algebra, and vise versa
→expressive power of the languages is identical

• A query language L is Relationally complete if


L can express any query that can be expressed in the relational calculus
Relational Calculus

• TRC and DRC are semantically similar


• In TRC, tuples share an equal status as variables, and field referencing
can be used to select tuple parts
• In DRC, formal variables are explicit
Tuple Relational Calculus

• Query: {T | P(T)}
• T is tuple variable
• P(T) is a formula that describes T
• Result, the set of all tuples t for which P(t) evaluates True.
• Find all sailors with a rating above 7.

• Atomic formula
• R.a op S.b , op is one of R.a op constant
Tuple Relational Calculus

• A logical language with variables ranging over tuples:


• { T | Cond }: return all tuples T that satisfy the condition Cond.
• { T | R(T) }: returns all tuples T such that T is a tuple in relation R.
• { T.name | F ACULT Y (T) AND T.DeptId = ‘CS’ }: returns the
values of name field of all faculty tuples with the value ’CS’ in their
department id field.
• The variable T is said to be free since it is not bound by a quantifier (for all,
exists).
• The result of this statement is a relation (or a set of tuples) that correspond
to all possible ways to satisfy this statement.
• Find all possible instances of T that make this statement true.
Tuple Relational Calculus

• Query: {T|P(T)}
• T is tuple variable
• P(T) is a formula that describes T
Result: the set of all tuples t for which P(t) evaluates True.
 Find all sailors with a rating above 7.
Operations In Tuple Relational Calculus

• ∧ - AND
• ∨ - OR
• ¬ - NOT
• ∃x – there exists x
• ∀x – for all x
Note: General power of 1st order predicate calculus – allow more flexible
expression formats
Tuple Relational Calculus
Tuple Relational Calculus
Examples

Consider relations for queries:


• Relation 1:
Examples
Relation 2:

Relation 3:
Examples

1. Find the loan number, branch, amount of loans of greater


than or equal to 10000 amount
{t| t ∈ loan ∧ t[amount]>=10000}
Domain Relational Calculus

• Query has the form:


 



x1, x2,..., xn | p x1, x2,..., xn




 
  


x1, x2,...,xn
Answer includes all tuples that
make the formula p x1, x2,..., xn 
 be true.
 
 

Formula is recursively defined, starting with simple atomic formulas


(getting tuples from relations or making comparisons of values), and
building bigger and better formulas using the logical connectives.
Domain Relational Calculus
Domain Relational Calculus

• Query has the form:


{ <x1,x2….xn>| p(<x1,x2….xn>)}
• Domain Variable – ranges over the values in the domain of some attribute
or is a constant
• Example: If the domain variable x1 maps to attribute - Name char(20)
then x1 ranges over all strings that are 20 characters long
Not just the strings values in the relation’s attribute
• Answer includes all tuples that make the formula p() true.
Domain Relational Calculus
Examples

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)}

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)}

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”)))}
Relational Calculus: Summary

• Relational algebra is more operational; useful as internal representation


for query evaluation plans.
• Relational calculus is non-operational, and users define queries in terms
of what they want, not in terms of how to compute it. (Declarativeness.)
• Algebra and safe calculus have same expressive power, leading to the
notion of relational completeness.
Comparison
FAQ

1. How does Tuple-oriented relational calculus differ from domain-oriented


relational calculus?
2. Define Relational Algebra and Relational Calculus
3. What is degree of a Relation?
4. What is a Relation Schema and a Relation?
5. List various Operators used in Relational Algebra and Calculus
References

OTHER REFRENCES
• https://cs.uwaterloo.ca/~tozsu/courses/CS348/notes/4b-calculus-handout-notes.pdf
• http://www.ccs.neu.edu/home/kathleen/classes/cs3200/4-RAAndRC.pdf
• https://www2.cs.sfu.ca/CourseCentral/354/louie/Chap3_practice.pdf
• http://www.nyu.edu/classes/jcf/CSCI-GA.2433-001_fa11/slides/session5/RelationalAlgebra-Re
lationalCalculus-SQL.pdf
• https://blog.inf.ed.ac.uk/da15/files/2015/01/inf1-da-15-t3.pdf
•Database System Concepts by Sudarshan, Korth(McGraw-HillEducation)

•Fundamentals of Database System By Elmasari & Navathe - PearsonEducation

•http://ecomputernotes.com/database-system/rdbms

•https://www.tutorialspoint.com/sql/sql-rdbms-concepts.htm

•https://www.studytonight.com/dbms/rdbms-concept
SUGGESTED BOOK REFERENCES
• Ramez Elmasri and Shamkant B. Navathe,“Fundamentals of Database System”, The
Benjamin / Cummings Publishing Co.
• Korth and Silberschatz Abraham, “Database SystemConcepts”, McGraw Hall.
• Pratt,”DBMS”, Cengage Learning.

You might also like