2 Relational Model Part 1of3
2 Relational Model Part 1of3
Example of a Relation
attributes
(or columns)
tuples
(or rows)
Attribute Types
The set of allowed values for each
attribute is called the domain of the
attribute
Attribute values are (normally)
required to be atomic; that is,
indivisible
The special value null is a member of
every domain. Indicated that the value
is “unknown”
The null value causes complications
in the definition of many operations
Relation Schema and Instance
A1, A2, …, An are attributes
D1 x D2 x … x Dn
Thus, a relation is a set of n-tuples (a , a , …, an) where
The current values (relation instance)1 of2a relation are
each ai by
specified Di a table
An element t of r is a tuple, represented by a row in a
table
Relations are Unordered
Relational algebra
Tuple relational calculus
Domain relational calculus
The above 3 pure languages are equivalent
in computing power
Relational Algebra Procedural language
Six basic operators
1.select: σ
2.project: ∏
3.union: ∪
4.set difference: –
5.Cartesian product: x
6.rename: ρ
Additional Operations
1. Set intersection
2. Natural join
3. Division
4. Assignment
Extended Relational-Algebra-Operations
1. Generalized Project
2. Aggregate Functions
3. Outer Join
Select Operation – selection of rows
(tuples)
Relation r
Relation r:
A,C (r)
Union of two relations
Relations r, s:
r s:
Set difference of two relations
Relations r, s:
r – s:
Set intersection of two relations
Relation r, s:
rs
Note: r s = r – (r – s)
joining two relations -- Cartesian-
product
Relations r, s:
r x s:
Cartesian-product – naming issue
Relations r, s: B
r x s: r.B s.B
Renaming a Table
Allows us to refer to a relation, (say E) by more than one name.
x (E)
Relations r
rxs
A=C (r x s)
Joining two relations – Natural
Join
Let r and s be relations on schemas R and S
respectively.
Then, the “natural join” of relations R and S is a
relation on schema R S obtained as follows:
Consider each pair of tuples tr from r and ts
from s.
If tr and ts have the same value on each of the
attributes in R S, add a tuple t to the result,
where
t has the same value as tr on r
Natural Join
r s