relational database design - university at buffalochomicki/562/main-design.pdf · boyce-codd normal...

51
Relational Database Design Jan Chomicki University at Buffalo Jan Chomicki () Relational database design 1 / 16

Upload: vandat

Post on 15-Aug-2018

227 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Relational Database Design - University at Buffalochomicki/562/main-design.pdf · Boyce-Codd Normal Form (BCNF) and 3NF BCNF A schema R is in BCNF if for every nontrivial FD X !A

Relational Database Design

Jan ChomickiUniversity at Buffalo

Jan Chomicki () Relational database design 1 / 16

Page 2: Relational Database Design - University at Buffalochomicki/562/main-design.pdf · Boyce-Codd Normal Form (BCNF) and 3NF BCNF A schema R is in BCNF if for every nontrivial FD X !A

Outline

1 Functional dependencies

2 Normal forms

3 Multivalued dependencies

Jan Chomicki () Relational database design 2 / 16

Page 3: Relational Database Design - University at Buffalochomicki/562/main-design.pdf · Boyce-Codd Normal Form (BCNF) and 3NF BCNF A schema R is in BCNF if for every nontrivial FD X !A

“Good” and “bad” database schemas

“Bad” schemaRepetition of information. Leads to redundancies, potential inconsistencies,and update anomalies.

Inability to represent information. Leads to anomalies in insertion anddeletion.

“Good” schema

relation schemas in normal form (redundancy- and anomaly-free): BCNF,3NF.

Schema decomposition

improving a bad schema

desirable properties:I lossless joinI dependency preservation

Jan Chomicki () Relational database design 3 / 16

Page 4: Relational Database Design - University at Buffalochomicki/562/main-design.pdf · Boyce-Codd Normal Form (BCNF) and 3NF BCNF A schema R is in BCNF if for every nontrivial FD X !A

“Good” and “bad” database schemas

“Bad” schemaRepetition of information. Leads to redundancies, potential inconsistencies,and update anomalies.

Inability to represent information. Leads to anomalies in insertion anddeletion.

“Good” schema

relation schemas in normal form (redundancy- and anomaly-free): BCNF,3NF.

Schema decomposition

improving a bad schema

desirable properties:I lossless joinI dependency preservation

Jan Chomicki () Relational database design 3 / 16

Page 5: Relational Database Design - University at Buffalochomicki/562/main-design.pdf · Boyce-Codd Normal Form (BCNF) and 3NF BCNF A schema R is in BCNF if for every nontrivial FD X !A

“Good” and “bad” database schemas

“Bad” schemaRepetition of information. Leads to redundancies, potential inconsistencies,and update anomalies.

Inability to represent information. Leads to anomalies in insertion anddeletion.

“Good” schema

relation schemas in normal form (redundancy- and anomaly-free): BCNF,3NF.

Schema decomposition

improving a bad schema

desirable properties:I lossless joinI dependency preservation

Jan Chomicki () Relational database design 3 / 16

Page 6: Relational Database Design - University at Buffalochomicki/562/main-design.pdf · Boyce-Codd Normal Form (BCNF) and 3NF BCNF A schema R is in BCNF if for every nontrivial FD X !A

“Good” and “bad” database schemas

“Bad” schemaRepetition of information. Leads to redundancies, potential inconsistencies,and update anomalies.

Inability to represent information. Leads to anomalies in insertion anddeletion.

“Good” schema

relation schemas in normal form (redundancy- and anomaly-free): BCNF,3NF.

Schema decomposition

improving a bad schema

desirable properties:I lossless joinI dependency preservation

Jan Chomicki () Relational database design 3 / 16

Page 7: Relational Database Design - University at Buffalochomicki/562/main-design.pdf · Boyce-Codd Normal Form (BCNF) and 3NF BCNF A schema R is in BCNF if for every nontrivial FD X !A

Integrity constraints

Functional dependencies

key constraints cannot express uniqueness properties holding in a propersubset of all attributes

key constraints need to be generalized to functional dependencies

Other constraintsnot relevant for decomposition

Jan Chomicki () Relational database design 4 / 16

Page 8: Relational Database Design - University at Buffalochomicki/562/main-design.pdf · Boyce-Codd Normal Form (BCNF) and 3NF BCNF A schema R is in BCNF if for every nontrivial FD X !A

Integrity constraints

Functional dependencies

key constraints cannot express uniqueness properties holding in a propersubset of all attributes

key constraints need to be generalized to functional dependencies

Other constraintsnot relevant for decomposition

Jan Chomicki () Relational database design 4 / 16

Page 9: Relational Database Design - University at Buffalochomicki/562/main-design.pdf · Boyce-Codd Normal Form (BCNF) and 3NF BCNF A schema R is in BCNF if for every nontrivial FD X !A

Integrity constraints

Functional dependencies

key constraints cannot express uniqueness properties holding in a propersubset of all attributes

key constraints need to be generalized to functional dependencies

Other constraintsnot relevant for decomposition

Jan Chomicki () Relational database design 4 / 16

Page 10: Relational Database Design - University at Buffalochomicki/562/main-design.pdf · Boyce-Codd Normal Form (BCNF) and 3NF BCNF A schema R is in BCNF if for every nontrivial FD X !A

Functional dependencies (FDs)

Notation

Relation schema R(A1, . . . ,An)

r is an instance of R

Sets of attributes of R: X ,Y ,Z , . . . ⊆ {A1, . . . ,An}A1 · · ·An instead of {A1, . . . ,An}.XY instead of X ∪ Y .

Functional dependency

syntax: X → Y

semantics: r satisfies X → Y if for all tuples t1, t2 ∈ r :

if t1[X ] = t2[X ], then also t1[Y ] = t2[Y ].

Jan Chomicki () Relational database design 5 / 16

Page 11: Relational Database Design - University at Buffalochomicki/562/main-design.pdf · Boyce-Codd Normal Form (BCNF) and 3NF BCNF A schema R is in BCNF if for every nontrivial FD X !A

Functional dependencies (FDs)

Notation

Relation schema R(A1, . . . ,An)

r is an instance of R

Sets of attributes of R: X ,Y ,Z , . . . ⊆ {A1, . . . ,An}A1 · · ·An instead of {A1, . . . ,An}.XY instead of X ∪ Y .

Functional dependency

syntax: X → Y

semantics: r satisfies X → Y if for all tuples t1, t2 ∈ r :

if t1[X ] = t2[X ], then also t1[Y ] = t2[Y ].

Jan Chomicki () Relational database design 5 / 16

Page 12: Relational Database Design - University at Buffalochomicki/562/main-design.pdf · Boyce-Codd Normal Form (BCNF) and 3NF BCNF A schema R is in BCNF if for every nontrivial FD X !A

Functional dependencies (FDs)

Notation

Relation schema R(A1, . . . ,An)

r is an instance of R

Sets of attributes of R: X ,Y ,Z , . . . ⊆ {A1, . . . ,An}A1 · · ·An instead of {A1, . . . ,An}.XY instead of X ∪ Y .

Functional dependency

syntax: X → Y

semantics: r satisfies X → Y if for all tuples t1, t2 ∈ r :

if t1[X ] = t2[X ], then also t1[Y ] = t2[Y ].

Jan Chomicki () Relational database design 5 / 16

Page 13: Relational Database Design - University at Buffalochomicki/562/main-design.pdf · Boyce-Codd Normal Form (BCNF) and 3NF BCNF A schema R is in BCNF if for every nontrivial FD X !A

Dependency implication

Implication

A set of FDs F implies an FD X → Y , if every relation instance that satisfies allthe dependencies in F , also satisfies X → Y .

Notation

F |= X → Y (F implies X → Y ).

Closure of a dependency set F

The set of dependencies implied by F .

Notation

F+ = {X → Y : F |= X → Y }.

Jan Chomicki () Relational database design 6 / 16

Page 14: Relational Database Design - University at Buffalochomicki/562/main-design.pdf · Boyce-Codd Normal Form (BCNF) and 3NF BCNF A schema R is in BCNF if for every nontrivial FD X !A

Dependency implication

Implication

A set of FDs F implies an FD X → Y , if every relation instance that satisfies allthe dependencies in F , also satisfies X → Y .

Notation

F |= X → Y (F implies X → Y ).

Closure of a dependency set F

The set of dependencies implied by F .

Notation

F+ = {X → Y : F |= X → Y }.

Jan Chomicki () Relational database design 6 / 16

Page 15: Relational Database Design - University at Buffalochomicki/562/main-design.pdf · Boyce-Codd Normal Form (BCNF) and 3NF BCNF A schema R is in BCNF if for every nontrivial FD X !A

Dependency implication

Implication

A set of FDs F implies an FD X → Y , if every relation instance that satisfies allthe dependencies in F , also satisfies X → Y .

Notation

F |= X → Y (F implies X → Y ).

Closure of a dependency set F

The set of dependencies implied by F .

Notation

F+ = {X → Y : F |= X → Y }.

Jan Chomicki () Relational database design 6 / 16

Page 16: Relational Database Design - University at Buffalochomicki/562/main-design.pdf · Boyce-Codd Normal Form (BCNF) and 3NF BCNF A schema R is in BCNF if for every nontrivial FD X !A

Keys

Key

X ⊆ {A1, . . . ,An} is a key of R if:

1 the dependency X → A1 · · ·An is in F+.

2 for all proper subsets Y of X , the dependency Y → A1 · · ·An is not in F+.

Related notionssuperkey: superset of a key.

primary key: one designated key.

candidate key: one of the keys.

Jan Chomicki () Relational database design 7 / 16

Page 17: Relational Database Design - University at Buffalochomicki/562/main-design.pdf · Boyce-Codd Normal Form (BCNF) and 3NF BCNF A schema R is in BCNF if for every nontrivial FD X !A

Keys

Key

X ⊆ {A1, . . . ,An} is a key of R if:

1 the dependency X → A1 · · ·An is in F+.

2 for all proper subsets Y of X , the dependency Y → A1 · · ·An is not in F+.

Related notionssuperkey: superset of a key.

primary key: one designated key.

candidate key: one of the keys.

Jan Chomicki () Relational database design 7 / 16

Page 18: Relational Database Design - University at Buffalochomicki/562/main-design.pdf · Boyce-Codd Normal Form (BCNF) and 3NF BCNF A schema R is in BCNF if for every nontrivial FD X !A

Keys

Key

X ⊆ {A1, . . . ,An} is a key of R if:

1 the dependency X → A1 · · ·An is in F+.

2 for all proper subsets Y of X , the dependency Y → A1 · · ·An is not in F+.

Related notionssuperkey: superset of a key.

primary key: one designated key.

candidate key: one of the keys.

Jan Chomicki () Relational database design 7 / 16

Page 19: Relational Database Design - University at Buffalochomicki/562/main-design.pdf · Boyce-Codd Normal Form (BCNF) and 3NF BCNF A schema R is in BCNF if for every nontrivial FD X !A

Inference of functional dependencies

Dependency inference

How to tell whether X → Y ∈ F+?

Inference rules (Armstrong axioms)

1 reflexivity: infer X → Y if Y ⊆ X ⊆ attrs(R) (trivial dependency)

2 augmentation: From X → Y infer XZ → YZ if Z ⊆ attrs(R)

3 transitivity: From X → Y and Y → Z , infer X → Z .

Jan Chomicki () Relational database design 8 / 16

Page 20: Relational Database Design - University at Buffalochomicki/562/main-design.pdf · Boyce-Codd Normal Form (BCNF) and 3NF BCNF A schema R is in BCNF if for every nontrivial FD X !A

Inference of functional dependencies

Dependency inference

How to tell whether X → Y ∈ F+?

Inference rules (Armstrong axioms)

1 reflexivity: infer X → Y if Y ⊆ X ⊆ attrs(R) (trivial dependency)

2 augmentation: From X → Y infer XZ → YZ if Z ⊆ attrs(R)

3 transitivity: From X → Y and Y → Z , infer X → Z .

Jan Chomicki () Relational database design 8 / 16

Page 21: Relational Database Design - University at Buffalochomicki/562/main-design.pdf · Boyce-Codd Normal Form (BCNF) and 3NF BCNF A schema R is in BCNF if for every nontrivial FD X !A

Inference of functional dependencies

Dependency inference

How to tell whether X → Y ∈ F+?

Inference rules (Armstrong axioms)

1 reflexivity: infer X → Y if Y ⊆ X ⊆ attrs(R) (trivial dependency)

2 augmentation: From X → Y infer XZ → YZ if Z ⊆ attrs(R)

3 transitivity: From X → Y and Y → Z , infer X → Z .

Jan Chomicki () Relational database design 8 / 16

Page 22: Relational Database Design - University at Buffalochomicki/562/main-design.pdf · Boyce-Codd Normal Form (BCNF) and 3NF BCNF A schema R is in BCNF if for every nontrivial FD X !A

Properties of axioms

Armstrong axioms are:

sound: if X → Y is derived from F , then X → Y ∈ F+.

complete: if X → Y ∈ F+, then X → Y is derived from F .

Additional (implied) inference rules

4. union: from X → Y and X → Z , infer X → YZ

5. decomposition: from X → Y infer X → Z , if Z ⊆ Y

Jan Chomicki () Relational database design 9 / 16

Page 23: Relational Database Design - University at Buffalochomicki/562/main-design.pdf · Boyce-Codd Normal Form (BCNF) and 3NF BCNF A schema R is in BCNF if for every nontrivial FD X !A

Properties of axioms

Armstrong axioms are:

sound: if X → Y is derived from F , then X → Y ∈ F+.

complete: if X → Y ∈ F+, then X → Y is derived from F .

Additional (implied) inference rules

4. union: from X → Y and X → Z , infer X → YZ

5. decomposition: from X → Y infer X → Z , if Z ⊆ Y

Jan Chomicki () Relational database design 9 / 16

Page 24: Relational Database Design - University at Buffalochomicki/562/main-design.pdf · Boyce-Codd Normal Form (BCNF) and 3NF BCNF A schema R is in BCNF if for every nontrivial FD X !A

Properties of axioms

Armstrong axioms are:

sound: if X → Y is derived from F , then X → Y ∈ F+.

complete: if X → Y ∈ F+, then X → Y is derived from F .

Additional (implied) inference rules

4. union: from X → Y and X → Z , infer X → YZ

5. decomposition: from X → Y infer X → Z , if Z ⊆ Y

Jan Chomicki () Relational database design 9 / 16

Page 25: Relational Database Design - University at Buffalochomicki/562/main-design.pdf · Boyce-Codd Normal Form (BCNF) and 3NF BCNF A schema R is in BCNF if for every nontrivial FD X !A

Boyce-Codd Normal Form (BCNF) and 3NF

BCNFA schema R is in BCNF if for every nontrivial FD X → A ∈ F , X contains a keyof R.

Each instance of a relation schema which is in BCNF does not contain aredundancy (that can be detected using FDs alone).

3NFR is in 3NF if for every nontrivial FD X → A ∈ F :

X contains a key of R, or

A is part of some key of R.

BCNF vs. 3NFif R is in BCNF, it is also in 3NF

there are relations that are in 3NF but not in BCNF.

Jan Chomicki () Relational database design 10 / 16

Page 26: Relational Database Design - University at Buffalochomicki/562/main-design.pdf · Boyce-Codd Normal Form (BCNF) and 3NF BCNF A schema R is in BCNF if for every nontrivial FD X !A

Boyce-Codd Normal Form (BCNF) and 3NF

BCNFA schema R is in BCNF if for every nontrivial FD X → A ∈ F , X contains a keyof R.

Each instance of a relation schema which is in BCNF does not contain aredundancy (that can be detected using FDs alone).

3NFR is in 3NF if for every nontrivial FD X → A ∈ F :

X contains a key of R, or

A is part of some key of R.

BCNF vs. 3NFif R is in BCNF, it is also in 3NF

there are relations that are in 3NF but not in BCNF.

Jan Chomicki () Relational database design 10 / 16

Page 27: Relational Database Design - University at Buffalochomicki/562/main-design.pdf · Boyce-Codd Normal Form (BCNF) and 3NF BCNF A schema R is in BCNF if for every nontrivial FD X !A

Boyce-Codd Normal Form (BCNF) and 3NF

BCNFA schema R is in BCNF if for every nontrivial FD X → A ∈ F , X contains a keyof R.

Each instance of a relation schema which is in BCNF does not contain aredundancy (that can be detected using FDs alone).

3NFR is in 3NF if for every nontrivial FD X → A ∈ F :

X contains a key of R, or

A is part of some key of R.

BCNF vs. 3NFif R is in BCNF, it is also in 3NF

there are relations that are in 3NF but not in BCNF.

Jan Chomicki () Relational database design 10 / 16

Page 28: Relational Database Design - University at Buffalochomicki/562/main-design.pdf · Boyce-Codd Normal Form (BCNF) and 3NF BCNF A schema R is in BCNF if for every nontrivial FD X !A

Boyce-Codd Normal Form (BCNF) and 3NF

BCNFA schema R is in BCNF if for every nontrivial FD X → A ∈ F , X contains a keyof R.

Each instance of a relation schema which is in BCNF does not contain aredundancy (that can be detected using FDs alone).

3NFR is in 3NF if for every nontrivial FD X → A ∈ F :

X contains a key of R, or

A is part of some key of R.

BCNF vs. 3NFif R is in BCNF, it is also in 3NF

there are relations that are in 3NF but not in BCNF.

Jan Chomicki () Relational database design 10 / 16

Page 29: Relational Database Design - University at Buffalochomicki/562/main-design.pdf · Boyce-Codd Normal Form (BCNF) and 3NF BCNF A schema R is in BCNF if for every nontrivial FD X !A

Boyce-Codd Normal Form (BCNF) and 3NF

BCNFA schema R is in BCNF if for every nontrivial FD X → A ∈ F , X contains a keyof R.

Each instance of a relation schema which is in BCNF does not contain aredundancy (that can be detected using FDs alone).

3NFR is in 3NF if for every nontrivial FD X → A ∈ F :

X contains a key of R, or

A is part of some key of R.

BCNF vs. 3NFif R is in BCNF, it is also in 3NF

there are relations that are in 3NF but not in BCNF.

Jan Chomicki () Relational database design 10 / 16

Page 30: Relational Database Design - University at Buffalochomicki/562/main-design.pdf · Boyce-Codd Normal Form (BCNF) and 3NF BCNF A schema R is in BCNF if for every nontrivial FD X !A

Decompositions

Decomposition

Replacement of a relation schema R by two relation schema R1 and R2 such thatR = R1 ∪ R2.

Lossless-join decomposition

(R1,R2) is a lossless-join decomposition of R with respect to a set of FDs F if forevery instance r of R that satisfies F :

πR1(r) 1 πR2(r) = r .

A simple criterion for checking whether a decomposition (R1,R2) is lossless-join:

R1 ∩ R2 → R1 ∈ F+, or

R1 ∩ R2 → R2 ∈ F+.

Decomposition into more than two schemas

generalized definition

more complex losslessness test

Jan Chomicki () Relational database design 11 / 16

Page 31: Relational Database Design - University at Buffalochomicki/562/main-design.pdf · Boyce-Codd Normal Form (BCNF) and 3NF BCNF A schema R is in BCNF if for every nontrivial FD X !A

Decompositions

Decomposition

Replacement of a relation schema R by two relation schema R1 and R2 such thatR = R1 ∪ R2.

Lossless-join decomposition

(R1,R2) is a lossless-join decomposition of R with respect to a set of FDs F if forevery instance r of R that satisfies F :

πR1(r) 1 πR2(r) = r .

A simple criterion for checking whether a decomposition (R1,R2) is lossless-join:

R1 ∩ R2 → R1 ∈ F+, or

R1 ∩ R2 → R2 ∈ F+.

Decomposition into more than two schemas

generalized definition

more complex losslessness test

Jan Chomicki () Relational database design 11 / 16

Page 32: Relational Database Design - University at Buffalochomicki/562/main-design.pdf · Boyce-Codd Normal Form (BCNF) and 3NF BCNF A schema R is in BCNF if for every nontrivial FD X !A

Decompositions

Decomposition

Replacement of a relation schema R by two relation schema R1 and R2 such thatR = R1 ∪ R2.

Lossless-join decomposition

(R1,R2) is a lossless-join decomposition of R with respect to a set of FDs F if forevery instance r of R that satisfies F :

πR1(r) 1 πR2(r) = r .

A simple criterion for checking whether a decomposition (R1,R2) is lossless-join:

R1 ∩ R2 → R1 ∈ F+, or

R1 ∩ R2 → R2 ∈ F+.

Decomposition into more than two schemas

generalized definition

more complex losslessness test

Jan Chomicki () Relational database design 11 / 16

Page 33: Relational Database Design - University at Buffalochomicki/562/main-design.pdf · Boyce-Codd Normal Form (BCNF) and 3NF BCNF A schema R is in BCNF if for every nontrivial FD X !A

Decompositions

Decomposition

Replacement of a relation schema R by two relation schema R1 and R2 such thatR = R1 ∪ R2.

Lossless-join decomposition

(R1,R2) is a lossless-join decomposition of R with respect to a set of FDs F if forevery instance r of R that satisfies F :

πR1(r) 1 πR2(r) = r .

A simple criterion for checking whether a decomposition (R1,R2) is lossless-join:

R1 ∩ R2 → R1 ∈ F+, or

R1 ∩ R2 → R2 ∈ F+.

Decomposition into more than two schemas

generalized definition

more complex losslessness test

Jan Chomicki () Relational database design 11 / 16

Page 34: Relational Database Design - University at Buffalochomicki/562/main-design.pdf · Boyce-Codd Normal Form (BCNF) and 3NF BCNF A schema R is in BCNF if for every nontrivial FD X !A

Decompositions

Decomposition

Replacement of a relation schema R by two relation schema R1 and R2 such thatR = R1 ∪ R2.

Lossless-join decomposition

(R1,R2) is a lossless-join decomposition of R with respect to a set of FDs F if forevery instance r of R that satisfies F :

πR1(r) 1 πR2(r) = r .

A simple criterion for checking whether a decomposition (R1,R2) is lossless-join:

R1 ∩ R2 → R1 ∈ F+, or

R1 ∩ R2 → R2 ∈ F+.

Decomposition into more than two schemas

generalized definition

more complex losslessness test

Jan Chomicki () Relational database design 11 / 16

Page 35: Relational Database Design - University at Buffalochomicki/562/main-design.pdf · Boyce-Codd Normal Form (BCNF) and 3NF BCNF A schema R is in BCNF if for every nontrivial FD X !A

Dependency preservation

Dependencies associated with relation schema R1 and R2 in a decomposition(R1,R2):

FR1 = {X → Y |X → Y ∈ F+ ∧ XY ⊆ R1}

FR2 = {X → Y |X → Y ∈ F+ ∧ XY ⊆ R2}.

(R1,R2) preserves a dependency f iff f ∈ (FR1 ∪ FR2)+.

Jan Chomicki () Relational database design 12 / 16

Page 36: Relational Database Design - University at Buffalochomicki/562/main-design.pdf · Boyce-Codd Normal Form (BCNF) and 3NF BCNF A schema R is in BCNF if for every nontrivial FD X !A

Dependency preservation

Dependencies associated with relation schema R1 and R2 in a decomposition(R1,R2):

FR1 = {X → Y |X → Y ∈ F+ ∧ XY ⊆ R1}

FR2 = {X → Y |X → Y ∈ F+ ∧ XY ⊆ R2}.

(R1,R2) preserves a dependency f iff f ∈ (FR1 ∪ FR2)+.

Jan Chomicki () Relational database design 12 / 16

Page 37: Relational Database Design - University at Buffalochomicki/562/main-design.pdf · Boyce-Codd Normal Form (BCNF) and 3NF BCNF A schema R is in BCNF if for every nontrivial FD X !A

Dependency preservation

Dependencies associated with relation schema R1 and R2 in a decomposition(R1,R2):

FR1 = {X → Y |X → Y ∈ F+ ∧ XY ⊆ R1}

FR2 = {X → Y |X → Y ∈ F+ ∧ XY ⊆ R2}.

(R1,R2) preserves a dependency f iff f ∈ (FR1 ∪ FR2)+.

Jan Chomicki () Relational database design 12 / 16

Page 38: Relational Database Design - University at Buffalochomicki/562/main-design.pdf · Boyce-Codd Normal Form (BCNF) and 3NF BCNF A schema R is in BCNF if for every nontrivial FD X !A

Decomposition into BCNF

Algorithm: decomposition of schema R1 For some nontrivial nonkey dependency X → A in F+:

I create a relation schema R1 with the set of attributes XA and FDs FR1 .I create a relation schema R2 with the set of attributes R − {A} and FDs FR2 .

2 Decompose further the resulting schemas which are not in BCNF.

This algorithm produces a lossless-join decomposition into BCNF which does nothave to preserve dependencies.

Jan Chomicki () Relational database design 13 / 16

Page 39: Relational Database Design - University at Buffalochomicki/562/main-design.pdf · Boyce-Codd Normal Form (BCNF) and 3NF BCNF A schema R is in BCNF if for every nontrivial FD X !A

Decomposition into BCNF

Algorithm: decomposition of schema R1 For some nontrivial nonkey dependency X → A in F+:

I create a relation schema R1 with the set of attributes XA and FDs FR1 .I create a relation schema R2 with the set of attributes R − {A} and FDs FR2 .

2 Decompose further the resulting schemas which are not in BCNF.

This algorithm produces a lossless-join decomposition into BCNF which does nothave to preserve dependencies.

Jan Chomicki () Relational database design 13 / 16

Page 40: Relational Database Design - University at Buffalochomicki/562/main-design.pdf · Boyce-Codd Normal Form (BCNF) and 3NF BCNF A schema R is in BCNF if for every nontrivial FD X !A

Decomposition into BCNF

Algorithm: decomposition of schema R1 For some nontrivial nonkey dependency X → A in F+:

I create a relation schema R1 with the set of attributes XA and FDs FR1 .I create a relation schema R2 with the set of attributes R − {A} and FDs FR2 .

2 Decompose further the resulting schemas which are not in BCNF.

This algorithm produces a lossless-join decomposition into BCNF which does nothave to preserve dependencies.

Jan Chomicki () Relational database design 13 / 16

Page 41: Relational Database Design - University at Buffalochomicki/562/main-design.pdf · Boyce-Codd Normal Form (BCNF) and 3NF BCNF A schema R is in BCNF if for every nontrivial FD X !A

Decomposition (synthesis) into 3NF

Minimal basis F ′ for F

set of FDs equivalent to F (F+ = (F ′)+),

all FDs in F ′ are of the form X → A where A is a single attribute,

further simplification by removing dependencies or attributes fromdependencies in F ′ yields a set of FDs inequivalent to F .

Algorithm: 3NF synthesis1 Create a minimal basis F ′.

2 Create a relation with attributes XA for every dependency X → A ∈ F ′.

3 Create a relation X for some key X of R.

4 Remove redundancies.

This algorithm produces a lossless-join decomposition into 3NF which preservesdependencies.

Jan Chomicki () Relational database design 14 / 16

Page 42: Relational Database Design - University at Buffalochomicki/562/main-design.pdf · Boyce-Codd Normal Form (BCNF) and 3NF BCNF A schema R is in BCNF if for every nontrivial FD X !A

Decomposition (synthesis) into 3NF

Minimal basis F ′ for F

set of FDs equivalent to F (F+ = (F ′)+),

all FDs in F ′ are of the form X → A where A is a single attribute,

further simplification by removing dependencies or attributes fromdependencies in F ′ yields a set of FDs inequivalent to F .

Algorithm: 3NF synthesis1 Create a minimal basis F ′.

2 Create a relation with attributes XA for every dependency X → A ∈ F ′.

3 Create a relation X for some key X of R.

4 Remove redundancies.

This algorithm produces a lossless-join decomposition into 3NF which preservesdependencies.

Jan Chomicki () Relational database design 14 / 16

Page 43: Relational Database Design - University at Buffalochomicki/562/main-design.pdf · Boyce-Codd Normal Form (BCNF) and 3NF BCNF A schema R is in BCNF if for every nontrivial FD X !A

Decomposition (synthesis) into 3NF

Minimal basis F ′ for F

set of FDs equivalent to F (F+ = (F ′)+),

all FDs in F ′ are of the form X → A where A is a single attribute,

further simplification by removing dependencies or attributes fromdependencies in F ′ yields a set of FDs inequivalent to F .

Algorithm: 3NF synthesis1 Create a minimal basis F ′.

2 Create a relation with attributes XA for every dependency X → A ∈ F ′.

3 Create a relation X for some key X of R.

4 Remove redundancies.

This algorithm produces a lossless-join decomposition into 3NF which preservesdependencies.

Jan Chomicki () Relational database design 14 / 16

Page 44: Relational Database Design - University at Buffalochomicki/562/main-design.pdf · Boyce-Codd Normal Form (BCNF) and 3NF BCNF A schema R is in BCNF if for every nontrivial FD X !A

Decomposition (synthesis) into 3NF

Minimal basis F ′ for F

set of FDs equivalent to F (F+ = (F ′)+),

all FDs in F ′ are of the form X → A where A is a single attribute,

further simplification by removing dependencies or attributes fromdependencies in F ′ yields a set of FDs inequivalent to F .

Algorithm: 3NF synthesis1 Create a minimal basis F ′.

2 Create a relation with attributes XA for every dependency X → A ∈ F ′.

3 Create a relation X for some key X of R.

4 Remove redundancies.

This algorithm produces a lossless-join decomposition into 3NF which preservesdependencies.

Jan Chomicki () Relational database design 14 / 16

Page 45: Relational Database Design - University at Buffalochomicki/562/main-design.pdf · Boyce-Codd Normal Form (BCNF) and 3NF BCNF A schema R is in BCNF if for every nontrivial FD X !A

Multivalued dependencies (MVDs)

Notation

Relation schema R(A1, . . . ,An).

r is an instance of R

Sets of attributes: X ,Y ,Z , . . . ⊆ {A1, . . . ,An}.

Multivalued dependency

syntax: a pair X →→ Y .

semantics: r satisfies X →→ Y if for all tuples t1, t2 ∈ r :

if t1[X ] = t2[X ], then there is a tuple t3 ∈ r such thatt3[XY ] = t1[XY ] and t3[Z ] = t2[Z ],

where Z = {A1, . . . ,An} − XY .

Implication

Defined in the same way as for FDs.

Jan Chomicki () Relational database design 15 / 16

Page 46: Relational Database Design - University at Buffalochomicki/562/main-design.pdf · Boyce-Codd Normal Form (BCNF) and 3NF BCNF A schema R is in BCNF if for every nontrivial FD X !A

Multivalued dependencies (MVDs)

Notation

Relation schema R(A1, . . . ,An).

r is an instance of R

Sets of attributes: X ,Y ,Z , . . . ⊆ {A1, . . . ,An}.

Multivalued dependency

syntax: a pair X →→ Y .

semantics: r satisfies X →→ Y if for all tuples t1, t2 ∈ r :

if t1[X ] = t2[X ], then there is a tuple t3 ∈ r such thatt3[XY ] = t1[XY ] and t3[Z ] = t2[Z ],

where Z = {A1, . . . ,An} − XY .

Implication

Defined in the same way as for FDs.

Jan Chomicki () Relational database design 15 / 16

Page 47: Relational Database Design - University at Buffalochomicki/562/main-design.pdf · Boyce-Codd Normal Form (BCNF) and 3NF BCNF A schema R is in BCNF if for every nontrivial FD X !A

Multivalued dependencies (MVDs)

Notation

Relation schema R(A1, . . . ,An).

r is an instance of R

Sets of attributes: X ,Y ,Z , . . . ⊆ {A1, . . . ,An}.

Multivalued dependency

syntax: a pair X →→ Y .

semantics: r satisfies X →→ Y if for all tuples t1, t2 ∈ r :

if t1[X ] = t2[X ], then there is a tuple t3 ∈ r such thatt3[XY ] = t1[XY ] and t3[Z ] = t2[Z ],

where Z = {A1, . . . ,An} − XY .

Implication

Defined in the same way as for FDs.

Jan Chomicki () Relational database design 15 / 16

Page 48: Relational Database Design - University at Buffalochomicki/562/main-design.pdf · Boyce-Codd Normal Form (BCNF) and 3NF BCNF A schema R is in BCNF if for every nontrivial FD X !A

Multivalued dependencies (MVDs)

Notation

Relation schema R(A1, . . . ,An).

r is an instance of R

Sets of attributes: X ,Y ,Z , . . . ⊆ {A1, . . . ,An}.

Multivalued dependency

syntax: a pair X →→ Y .

semantics: r satisfies X →→ Y if for all tuples t1, t2 ∈ r :

if t1[X ] = t2[X ], then there is a tuple t3 ∈ r such thatt3[XY ] = t1[XY ] and t3[Z ] = t2[Z ],

where Z = {A1, . . . ,An} − XY .

Implication

Defined in the same way as for FDs.

Jan Chomicki () Relational database design 15 / 16

Page 49: Relational Database Design - University at Buffalochomicki/562/main-design.pdf · Boyce-Codd Normal Form (BCNF) and 3NF BCNF A schema R is in BCNF if for every nontrivial FD X !A

Fourth Normal Form (4NF)

F is the set of FDs and MVDs associated with a relation schemaR = {A1, . . . ,An}.

4NFR is in 4NF if for every multivalued dependency X →→ Y entailed by F :

Y ⊆ X or XY = {A1, . . . ,An} (trivial MVD), or

X contains a key of R.

Jan Chomicki () Relational database design 16 / 16

Page 50: Relational Database Design - University at Buffalochomicki/562/main-design.pdf · Boyce-Codd Normal Form (BCNF) and 3NF BCNF A schema R is in BCNF if for every nontrivial FD X !A

Fourth Normal Form (4NF)

F is the set of FDs and MVDs associated with a relation schemaR = {A1, . . . ,An}.

4NFR is in 4NF if for every multivalued dependency X →→ Y entailed by F :

Y ⊆ X or XY = {A1, . . . ,An} (trivial MVD), or

X contains a key of R.

Jan Chomicki () Relational database design 16 / 16

Page 51: Relational Database Design - University at Buffalochomicki/562/main-design.pdf · Boyce-Codd Normal Form (BCNF) and 3NF BCNF A schema R is in BCNF if for every nontrivial FD X !A

Fourth Normal Form (4NF)

F is the set of FDs and MVDs associated with a relation schemaR = {A1, . . . ,An}.

4NFR is in 4NF if for every multivalued dependency X →→ Y entailed by F :

Y ⊆ X or XY = {A1, . . . ,An} (trivial MVD), or

X contains a key of R.

Jan Chomicki () Relational database design 16 / 16