Professional Documents
Culture Documents
Yonas Y.
Outline
Domain Relational
Calculus
Chapter 4
Formal Relational Query Languages
Yonas Y.
yonas.yehualaeshet@aait.edu.et
AAiT - SECE 1
Chapter 4
Yonas Y.
Outline
Domain Relational
Calculus
AAiT - SECE 2
Chapter 4
Outline
AAiT - SECE 3
Chapter 4
Outline
I Defined as:
σp (r ) = {t | t ∈ r and p(t)}
AAiT - SECE 4
Chapter 4
Yonas Y.
Outline
AAiT - SECE 5
Chapter 4
Outline
Domain Relational
I Notation: Calculus
Q
A1 ,A2 ,··· ,Ak (r )
I
AAiT - SECE 6
Chapter 4
Outline
r ∪ s = {t | t ∈ r or t ∈ s} Domain Relational
Calculus
For r ∪ s to be valid.
Outline
The set-difference operation, allows us to find tuples that are in The Relational Algebra
Outline
Check compatibility.
Note: r ∩ s = r - (r - s).
AAiT - SECE 9
Chapter 4
Outline
I Notation: r × s
I Defined as:
r × s = {t q | t ∈ r and q ∈ s}
Assume that attributes of r (R) and s(S) are disjoint. (That is,
R ∩ S = ∅).
AAiT - SECE 10
Chapter 4
Outline
Domain Relational
I Allows us to refer to a relation by more than one name. Calculus
Example:
ρx (E )
I returns the expression E under the name x.
returns the result of expression E under the name x, and with the
attributes renamed to A1 , A2, · · · , An .
AAiT - SECE 11
Chapter 4
Yonas Y.
Outline
Example: Consider the query ”Find the highest salary in the
The Relational Algebra
university.”
The Tuple Relational
Calculus
1. Step 1: Compute first a temporary relation consisting of
Domain Relational
those salaries that are not the largest. Calculus
Q
instructor .salary (σinstructor .salary <d.salary (instructor ×
ρd (instructor )))
AAiT - SECE 12
Chapter 4
Outline
Domain Relational
Calculus
{t | P(t)}
AAiT - SECE 13
Chapter 4
Outline
Domain Relational
2. Set of comparison operators: (e.g., <, ≤, =, 6=, >, ≥). Calculus
5. Set of quantifiers:
I ∃t ∈ r (Q(t)) ≡ ”there exists” a tuple t in relation r such
that predicate Q(t) is true.
I ∀t ∈ r (Q(t)) ≡ Q is true ”for all” tuples t in relation r .
AAiT - SECE 14
Chapter 4
Yonas Y.
Example: Find the ID, name, dept name, salary for instructors Outline
AAiT - SECE 15
Chapter 4
Yonas Y.
”Watson”))}
Example: Find the set of all courses taught in the Fall 2009
semester, or in the Spring 2010 semester, or both.
AAiT - SECE 16
Chapter 4
Outline
Domain Relational
Calculus
Example: Find all students who have taken all courses offered in
the Biology department.
{t | ∃r ∈ student(t[ID] = r [ID]∧
(∀u ∈ course(u[dept name] = ”Biology ” ⇒ ∃s ∈
takes(t[ID] = s[ID] ∧ s[course id] = u[course id]))}
AAiT - SECE 17
Chapter 4
Outline
It is possible to write tuple calculus expressions that generate The Tuple Relational
Calculus
AAiT - SECE 18
Chapter 4
Yonas Y.
Outline
Domain Relational
Calculus
{t | ∃r ∈ student(t[ID] = r [ID]∧
(∀u ∈ course(u[dept name] = ”Biology ” ⇒ ∃s ∈
takes(t[ID] = s[ID] ∧ s[course id] = u[course id]))}
AAiT - SECE 19
Chapter 4
Outline
Domain Relational
A nonprocedural query language equivalent in power to the tuple Calculus
relational calculus.
AAiT - SECE 20
Chapter 4
Outline
Domain Relational
{< i, n, d, s >|< i, n, d, s >∈ instructor ∧ s > 80000} Calculus
AAiT - SECE 21
Chapter 4
Yonas Y.
Outline
Example: Find the set of all courses taught in the Fall 2009 The Relational Algebra
s = ”Fall” ∧ y = 2009)
∨ ∃a, s, y , b, r , t(< c, a, s, y , b, r , t >∈ section ∧
s = ”Spring ” ∧ y = 2010)}
AAiT - SECE 22
Chapter 4
Outline
Domain Relational
Calculus
is safe if all of the following hold:
3. For every ”for all” subformula of the form ∀x(P1 (x)), the
subformula is true if and only if P1 (x) is true for all values x
from dom(P1 ).
AAiT - SECE 23
Chapter 4
Outline
AAiT - SECE 24
Chapter 4
Yonas Y.
Outline
Domain Relational
Questions?
AAiT - SECE 25