Professional Documents
Culture Documents
Relational
Calculus
Nguyễn Lê Hoàng Nhân
Nguyễn Phước Nguyên Phúc
Nguyễn Trần Minh Phước
What is Relational Calculus ?
Non-procedural query language
Tuple Domain
Relational Relational
Calculus Calculus
TUPLE RELATIONAL
CALCULUS
-Each EMPLOYEE tuple t that satisfies the condition t.Salary>50000 will be retrieved ( t.Salary =
t[salary] )
-To retrieve only some of the attributes—say, the first and last names—we write
t.Fname, t.Lname | EMPLOYEE(t) AND t.Salary>50000}
Expressions and Formulas in Tuple Relational Calculus
A general expression of the tuple relational calculus is of the form:
{t_1.A_j , t_2.A_k, ... , t_n.A_m | COND(t_1, t_2, ..., t_n, t_n+1, t_n+2, ..., t_n+m)}
-COND is a condition or formula of the tuple relational calculus. A formula is made up of predicate
calculus atoms, which can be one of the following:
∀
Universal Quantifiers: The universal quantifier denoted by is read as for all which
means that in a given set of tuples exactly all tuples satisfy a given condition.
∃
Existential Quantifiers: The existential quantifier denoted by is read as for all which
means that in a given set of tuples there is at least one occurrences whose value satisfy
a given condition.
∃
{t.Fname, t.Lname, t.Address | EMPLOYEE(t) AND ( d)(DEPARTMENT(d)
AND d.Dname="Research" AND d.Dnumber=t.Dno)}
Query 1: List the name and address of all employees who work for the
"Research" department.
∃
{t.Fname, t.Lname, t.Address | EMPLOYEE(t) AND ( d)(DEPARTMENT(d)
AND d.Dname="Research" AND d.Dnumber=t.Dno)}
∃
{t.Fname, t.Lname, t.Address | EMPLOYEE(t) AND ( d)(DEPARTMENT(d)
AND d.Dname="Research" AND d.Dnumber=t.Dno)}
∃ ∃
{ p.Pnumber | PROJECT(p) AND ((( e)( w)(EMPLOYEE(e) AND WORKS_ON(w)
AND w.Pno=p.Pnumber
AND e.Lname=‘Smith’ AND e.Ssn=w.Essn) )
OR
∃ ∃
(( m)( d)(EMPLOYEE(m) AND DEPARTMENT(d) AND p.Dnum=d.Dnumber
AND d.Mgr_ssn=m.Ssn AND m.Lname=‘Smith’)))}
Notation for Query
Graphs
Represent simple relational
Query Graph calculus queries
(select-project-join queries)
Example: Query Graph for Q2
Attribute to be retrived
Edges: Select and Join condition
Relation Node
Constant Node
Query graph Query tree
Transforming the Universal and
Existential Quantifiers
∀ ∃ is possible!
For implication
∀x)(P(x)) ⇒ (∃x)(P(x))
NOT (∃x)(P(x)) ⇒ NOT (∀x)(P(x))
Group 8
Tranforming between
Quantifier in Query
The formula in DRC is also made of atoms, variables, quantifier just like in TRC
Domain Relational Calculus
Example:
Query:
List the birth date and address of the employee whose name is ‘John B. Smith’
Some well-known transformation
It is possible to transform between Universal and Existetial quantifier
=> To get an equivalent expression
EXAMPLE QUERY TRANSFORM BETWEEN QUANTIFIER
Query: List the names of employees who work on all the projects
controlled by department number 5
Query:
List the names of employees who
work on all the projects controlled
by department number 5.
Domain Relational
Calculus
The expression:
Domain Relational Calculus
The formula is made of atoms, but it is slightly different from TRC:
The formula in DRC is also made of atoms, variables, quantifier just like in TRC
Domain Relational Calculus
Example:
Query:
List the birth date and address of the employee whose name is ‘John B. Smith’
Query: List the birth date and address of the employee whose name is ‘John B. Smith’
Solution:
Rewrite:
THE END