








Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
An introduction to the Relational Model, focusing on relations, keys, and database design. The Relational Model, introduced by Codd in 1970, is a mathematical foundation for databases using set theory. It models entity/object types and relationship types uniformly through relation schemata. the concept of relations, their graphical representation, and the development of a database application.
Typology: Schemes and Mind Maps
1 / 14
This page cannot be seen from the preview
Don't miss anything!









relation schemata).
Continent: name, area
attribute. Often, attributes also can have a null value.
Continent: name: VARCHAR(25), area: NUMBER
Continent:... ; Country:... ; City:... ; encompasses:... ; isMember:...
45
Every tuple represents an entity or a relationship. (name: Asia, area: 4.5E7)
Example:
Continent
name area
Europe 10523000
Africa 30221500
Asia 44614500
North America 24709000
South America 17840000
Australia 9000000
Relations: Example
Continent
name area
Europe 10523000
Africa 30221500
Asia 44614500
North America 24709000
South America 17840000
Australia 9000000
Country
name code population area ...
Germany D 83536115 356910
Sweden S 8900954 449964
Russia R 143666931 17075200
Poland PL 38642565 312683
Bolivia BOL 1098580 7165257
.. .. .. ..
encompasses
country continent percent
VARCHAR(4) VARCHAR(20) NUMBER
R Europe 20
R Asia 80
D Europe 100
......... - with referential integrity constraints
(to be explained later)
47
Graphical representation of the relational schema of the MONDIAL database (excerpt):
Organization
name
✄ abbrev
city ✄
country ✄
province ✄
established
isMember
✁ organization
✁ country
type
Country
name
✄ code ✄
capital ✄
province ✄
area
population
borders
✁ country
✁ country
length
located
✁ city
✁ country
✁ province
river ✄
lake ✄
sea ✄
City
✄ name
✄ country ✄
✄ province ✄
population
latitude
longitude
elevation
Province
name ✁
✁ country ✁
area
population
✁ capital
✁ capprov
geo_lake
lake ✄
✁ country
✁ province
Lake
✄ name
area
elevation
geo_river
river ✄
✁ country
✁ province
River
✄ name
length
✁ river
✁ lake
✁ sea
geo_sea
sea ✄
✁ country
✁ province
Sea
✄ name
depth
area
Starting with the ER schema, the relational schema is designed.
[Overview slide]
Let E ER
an entity type and R ER
a relationship type in the ERM.
1
n
1
n
(RER, {RO 1 : E 1 ,... , ROk : Ek}, {A 1 ,... , Am}) →
1
11
1
1 p 1
k
k 1
k
kpk
1
m
where {K i 1
ipi
} are the primary keys of E i
, 1 ≤ i ≤ k.
- Renaming of foreign key attributes is allowed
(e.g. coinciding attribute names in different referenced keys)
In case that k = 2 and a (1,1) relationship cardinality, the relation schema of the
relationship type and that of the entity type may be merged.
51
ER
1
n
i 1
ik
where {Ai 1
,... , Ai k
} ⊆ {A 1 ,... , An} are the scalar (i.e., not multivalued) attributes of EER –
multivalued attributes are mapped separately.
continent
name area
Asia 4.5E
Continent
name area
Europe 10523000
Africa 30221500
Asia 44614500
North America 24709000
South America 17840000
Australia 9000000
The candidate keys of the relation are the candidate keys of the entity type.
... one thing left:
Attributes of relations must only be single values.
ER
1
i
n
}) where A i
is a multivalued attribute
i
1
p
i
where {K 1
p
} are the primary keys of E.
(renaming is allowed, especially if there is only one key attribute)
1
p
i
} are the primary keys of the relation E_A i
code Country language
Languages
country language
D German
CH German
CH French
53
For weak entity types, the key attributes of the identifying entity type(s) must be added.
Country
in
name
area pop.
code
356910 83536115
Germany (^) D
Province
in Prov.
name
area (^) pop.
35751 10272069
Baden-W.
City
name pop.
Freiburg 198496
< 1 , 1 >
< 1 , 1 >
City
name country province population ...
Freiburg D Baden-W. 198496 ..
Berlin D Berlin 3472009 ..
Freiburg CH FR NULL ..
Cordoba E Andalucia 328326 ..
Cordoba RA Cordoba 1207774 ..
Recursive Symmetric Relationship Types
use role names as column names.
Store only one direction and create a symmetric SQL view from it (belongs to the
“external level” of the 3-level-architecture)
code (^) Country name
borders
< 0 , ∗ > < 0 , ∗ >
borders
country1 country2 length
SQL view (see later)
CREATE VIEW symmborders AS
(SELECT * FROM borders) UNION (SELECT country2, country1, length FROM borders)
57
Exercise 2.
Give a relational schema for the following ER schema:
Supplier
Product Part
delivers
< 0 , ∗ >
< 0 , ∗ > < 0 , ∗ >
component
< 0 , ∗ > belongs to
< 0 , ∗ > contains
nr
name
addr
nr
name
color weight
nr
name
amount date
(note the similarities with first-order logic)
i
X) consists of a name (here, R) and a finite set
1
m
m ≥ 1 of attributes.
X is the format of the schema.
(relation) schemata), optionally with integrity constraints.
m
} is relevant (i.e., for representation as a
table),
X is denoted as a vector [A 1
m
59
Consider a relation schema R(
X is associated to a (non-empty) domain of atomic values, called
dom(A).
X) := dom(A 1
) ×... × dom(A m
dom(continent.name) = VARCHAR, dom(continent.area) = NUMBER
dom(Continent) = VARCHAR × NUMBER
Note the following:
While in the ER model, the keys serve only for an intuitive modeling, in relational database
design they play an important role for the database performance and for the ability of the
database to incorporate and maintain key constraints.
The notion of keys is defined as for the ER model:
For a set
X of attributes of a relation schema R, a relation r ∈ Rel(
X) satisfies the key
constraint
K if for all tuples μ 1
, μ 2
∈ r:
If μ 1
K) = μ 2
K) (i.e., μ 1
and μ 2
coincide on the values of
K), then μ 1
= μ 2
More Concrete Requirements on Keys
(to be formalized on the next slides)
′
(
K satisfies the key property,
′ (
X of
the attributes of R, any subset
′ (
K satisfies the key property wrt.
′ .
[3rd Normal Form, cf. Slide 374; Example see Slide 67]
63
The relational model provides a more concise formalization of keys (cf. Slide 326 ff. on
Normalization Theory for details).
These are based on the definition of functional dependencies :
Given a relation R(
r satisfies the functional dependency (FD)
W if for all tuples μ 1 , μ 2 ∈ r,
μ 1
V ) = μ 2
V ) ⇒ μ 1
W ) = μ 2
W functionally depends on
Example 2.
Consider the relation schema Country(name, code, area, population, capital, capprov).
The following functional dependencies hold wrt. the intended application domain:
{code} → {name}, {name} → {code}
{code} → {area, population, capital, capprov}
{code} → {name, code, area, population, capital, capprov}
{name} → {name, code, area, population, capital, capprov} ✷
Keys (Cont’d)
In the schema, it is represented by underlining these attributes.
65
X is a possible key of R(
X) if
Additionally:
′ (
K satisfies the key property:
there is no subset
′ (
K s.t.
′ →
(otherwise: take
′ as key)
K): there is no subset
′ (
K s.t.
′ → A.
(otherwise: if there is some attribute that depends only on a part of the key, split this
relationship into a separate table, cf. example on Slide 67 and section on Normalization
Theory, Slide 326.)
Although looking formally, the second criterion is also easy to understand and prevents
bad/dangerous database design.
Consider relation schemata R 1
1
) and R 2
2
). Let
1
1
and
2
2
two attribute
vectors of the same length.
r 1
1
) and r 2
2
) satisfy an inclusion constraint R 1
1
2
2
if and only if for
all μ 1 ∈ r 1 there is a μ 2 ∈ r 2 s.t. μ 1 (
Y 1 ) = μ 2 (
Referential Integrity
2
is the key of R 2
, there is a referential integrity constraint from R 1
1
to R 2
2
1
is called a foreign key in R 1
that references R 2
2
Referential integrity constraints result from incorporating the keys of the participating entities
into the table that represents the relationship.
69
Semantics:
- “value exists, but is unknown”
(e.g., geo-coordinates of some cities)
- “value does not yet exist, but will exist in the future”
(e.g., inflation of a newly founded country)
- “attribute not applicable” (e.g. “last eruption date” for mountains other than volcanoes)
X is a mapping s.t.
for all A ∈
X, μ(A) ∈ dom(A) ∪ {null}.
A relation is called partial if it contains partial tuples.
Exercise 2.
Consider the relation schema R(
X), where
X = {A, B} and dom(A) = dom(B) = { 1 , 2 }.
X) and Rel(
X) violate the key constraint? ✷