Week 4
Formal Relational Query Language
Relational Algebra
Select
Project
Union
Difference
Intersection
Cartesian Product
Rename
Division Operation
Predicate Logic/ Predicate Calculus
Predicate
Proposition
Quantifiers
Universal Quantifiers
Existential Quantifiers
Tuple Relation Calculus (TRC)
Domain Relational Calculus (DRC)
Entity Relationship Diagrams
Relationship Types
Symbols
Formal Relational Query Language
Relational Algebra
Procedural and Algebra-based
Tuple Relational Calculus
Non-procedural and predicate calculus-based
Domain Relational Calculus
Non-procedural and predicate calculus-based
Relational Algebra
Created by Edgar F Codd at IBM in 1970
Week 4 1
Procedural language
Six basic operators
Select: σ
Project: Π
Union: ∪
Set Difference: –
Cartesian Product: X
Rename: ρ
Operators take one or two relations as input and generate a new relation as
output
Select
Project
Week 4 2
Union
Difference
Week 4 3
Intersection
Cartesian Product
Week 4 4
Rename
Division Operation
Week 4 5
Predicate Logic/ Predicate Calculus
Predicate
The predicate P can be considered as a function. It tells the truth value of the
statement P(x) at x.
Proposition
Once a value has been assigned to the variable x, the statement
P(x) becomes a proposition and has truth or false value.
📌 Tuple Relational Calculus and Domain Relational Calculus are based on
Predicate
Calculus
Quantifiers
Universal Quantifiers
The universal quantification of P(x) is the statement “P(x) for all values of x
in the domain”.
∀
The notation P(x) denotes the universal quantification of P(x). Here ∀ is called
the
∀
universal quantifier. P(x) is read as “for all x P(x)”.
Week 4 6
Existential Quantifiers
The existential quantification of P(x) is the statement ”There exists an
element x in the domain such that P(x)”.
∃
The notation P(x) denotes the existential quantification of P(x). Here is ∃
called the
∃
existential quantifier. P(x) is read as “There is at least one such x such that
P(x)”
Tuple Relation Calculus (TRC)
TRC is a non-procedural query language, where each query is of the form
t∣P (t)
where t = resulting tuples,
P(t) = known as predicate and these are the conditions that are used to fetch t.
∨
P(t) may have various conditions logically combined with OR ( ), AND ( ), NOT(¬).∧
It also uses quantifiers:
∃∈ t r(Q(t)) = “there exists” a tuple in t in relation r such that predicate Q(t) is true.
∀∈ t r(Q(t)) = Q(t) is true “for all” tuples in relation r.
💡 Example:
t∣∃s ∈ Student([Link] > 21 ∧ t.F name = s.F name)
Domain Relational Calculus (DRC)
A non-procedural query language equivalent in power to the tuple relational calculus
• Each query is an expression of the form:
< x1, x2, ..., xn > ∣P (x1, x2, ..., xn)
◦ x1 , x2 , ..., xn represent domain variables
◦ P represents a formula similar to that of the predicate calculus
Entity Relationship Diagrams
Week 4 7
Relationship Types
Week 4 8
Week 4 9
Symbols
Week 4 10
Week 4 11