Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
model
Functional dependencies
Normalization
Functional Dependencies
Definition:
– An integrity constraint between two sets of attributes
Think of it as a relationship between two sets of
attributes
Generalizes the concept of a key, where both X and Y
represent sets of attributes
X→Y
– X functionally determines Y
– Y is functionally determined by X
FD {X → Y}
i.e., when two tuples agree on their values for the X domains, they
agree on their values for the Y domains
{X} {Y}
1,2,a,0 m
1,2,a,0 m
Functional Dependencies
A B C D …
A1 B1 C1 D1 …
Determinant
A1 B1 C1 D2 …
AB → C
A1 B2 C2 D1 …
A2 B1 C3 D1 … Dependent
Functional Dependency Closure
Requirements:
– Every dependency has a single attribute for its right side
– No X → A in F can be replaced with Y → A where Y is a subset of
X and still have dependencies equivalent to F
– No dependency can be removed and still have a set of
dependency equivalent to F
Definition:
– If the right-hand (dependent) side of every FD in S involves just
one attribute, and
– if the left-hand (determinant) side of every FD in S is irreducible
(can’t discard another attribute without making a new set not
equivalent to S - aka, changing the closure of S+), and
– no FD in S can be discarded without changing the closure of S+,
then the set S of FDs is irreducible (minimal).
Example
Given:
A → B, ABCD → E, EF → G, EF → H, and ACDF → EG
First rewrite:
ACDF → E and ACDF → G
Then consider ACDF → G
(implied by: A → B, ABCD → E, and EF → G)
Delete it (and, in the same way, ACD → E replaces ABCD →
E)
Minimal Set: A → B, ACD → E, ACDF → G, and ACDF → H.
An SQL consideration:
If X functionally determines Y, then Y is functionally dependent on X.
So the SELECT contains the right side and where or group by contains the
left side of a Functional Dependency statement
Pay 2NF
The key, the whole key, and nothing but the key
Assumptions:
– FDs exist
– A designated primary key can be found
Remember, a key is a FD, but a FD is not always a key
A property of a relation schema indicating the type of
redundancy in the relation schema
The goal is to remove redundancy based on
dependencies
The desire is to minimize additional integrity
constraints
Normal Forms
Considerations:
– Relational design by analysis
– Normal forms are based on functional dependencies
(FDs)
– Intuitive, perhaps, but identifying a strictly controlled
procedure allows a programmatic process
– Should consider 2 additional properties
Lossless join (nonadditive join property)
– required
Dependency preservation property
– use when possible
Lossless Joins and Dependency
Preservation
PN PM
AD3111 20
PN PM D
IF1000 20
AD3111 20 A00
MA2100 10
MA2100 10 D11
OP1000 10
OP1000 10 D11
IF1000 20 A00
PM D
20 A00
10 D11
Sample Set
The key, the whole key, and nothing but the key
Assumptions:
– FDs exist
– A designated primary key can be found
Remember, a key is a FD, but a FD is not always
a key
A property of a relation schema indicating the
type of redundancy in the relation schema
The goal is to remove redundancy based on
dependencies
The desire is to minimize additional integrity
constraints
Normal Forms
Considerations:
– Relational design by analysis
– Normal forms are based on functional dependencies (FDs)
– Intuitive, perhaps, but identifying a strictly controlled
procedure allows a programmatic process
– Should consider 2 additional properties
Lossless join (nonadditive join property)
– required
Dependency preservation property
– use when possible
Lossless Joins and Dependency
Preservation
Definitions:
– Superkey –
R={A1,A2,…,An}
A set of attributes S ⊆ R
No 2 tuples (t1,t2) in any legal relation state r of R has t1[S]=t2[S]
– Key –
A superkey that is disqualified by any attribute being removed, &
Must be minimal (can’t remove another attribute without
disqualifying as key of R)
– Candidate Key –
A set of attributes in a relation satisfying key definition
– Primary Key –
Arbitrarily designated
– Primary Attribute –
A member of a candidate key
Levels of
Normalization
BCNF
3 NF
2 NF
1 NF
BCNF table
Requirements:
– 1NF disallows multivalued attributes, or composite
attributes, or their combinations, by requiring only single
atomic (indivisible) values in the domain of an attribute
– In other words, no “relation within relations”
Business Rules Example
1NF
PN AN PM D S
Staffing hours (S) are on a per
project activity (activities AD3111 20 20 A00 0.8
within projects) basis - AN AD3111 30 20 A00 1.5
Managers (PM) and their AD3111 40 20 A00 1
departments (D) are assigned AD3111 50 20 A00 1.25
to projects (PN)
– A department is assigned to a
AD3111 60 20 A00 0.75
project managers AD3111 70 20 A00 0.35
– A project manager is assigned MA2100 20 10 D11 0.5
to projects
MA2100 30 10 D11 1
OP1000 30 10 D11 0.25
IF1000 30 20 A00 1
IF1000 50 20 A00 0.5
IF1000 60 20 A00 0.5
Second Normal Form (2NF)
K X A
1NF
Staffing is on a per project activity ( and activities within projects)
basis
2NF
Managers and their departments are assigned to projects
{PN,AN→STAFF}
PN AN PM D S PN →{PM,DN} PN AN STAF
AD3111 20 20 A00 0.8 AD3111 20 F
0.8
AD3111 30 20 A00 1.5 AD3111 30 1.5
AD3111 40 20 A00 1 AD3111 40 1
AD3111 50 20 A00 1.25 AD3111 50 1.25
AD3111 60 20 A00 0.75 AD3111 60 .75
AD3111 70 20 A00 0.35 AD3111 70 .35
MA2100 20 10 D11 0.5 MA2100 20 .5
PN PM D
MA2100 30 10 D11 1 MA2100 30 1
AD3111 20 A0
OP1000 30 10 D11 0.25 0 OP1000 30 0.25
MA210 10 D1
IF1000 30 20 A00 1 0 1 IF1000 30 1
OP1000 10 D1
IF1000 50 20 A00 0.5 IF1000 50 .5
1
IF1000 60 20 A00 0.5 IF1000 20 A0
IF1000 60 .5
0
Third Normal Form (3NF)
X A
K
X
A department is assigned to a project manager
2NF A project manager is assigned to projects 3NF
PN PM
PN PM D PN→PM →D AD311 20
AD311 20 A0 1
MA210 10
1
MA210 10 0
D1 0
OP100 10
0
OP100 10 1
D1 0
IF1000 20
0
IF1000 20 1
A0
0
PM D
20 A0
10 0
D1
1