Docsity

Normalization - Data Base Management System - Lecture Slides, Slides of Database Management Systems (DBMS)

Partial preview of the text

Download Normalization - Data Base Management System - Lecture Slides and more Slides Database Management Systems (DBMS) in PDF only on Docsity!

BCNF & Lossless Decomposition

Normalization

 Review on Keys

  • superkey: a set of attributes which will uniquely

identify each tuple in a relation

  • candidate key: a minimal superkey
  • primary key: a chosen candidate key
  • secondary key: all the rest of candiate keys
  • prime attribute: an attribute that is a part of a

candidate key (key column)

  • nonprime attribute: a nonkey column

Functional Dependencies

  • Let R be a relation schema

α ⊆ R and β ⊆ R

  • The functional dependency

holds on R iff for any legal relations r (R), whenever two tuples t 1

and t 2 of r have same values for α, they have same values for β.

t 1 [α] = t 2 [α] ⇒ t 1 [ β ] = t 2 [ β ]

  • On this instance, A → B does NOT hold, but B → A does hold.

1 4 1 5 3 7

A B

1. Closure

• Given a set of functional dependencies, F, its

closure, F +^ , is all FDs that are implied by FDs in F.

• e.g. If A  B, and B  C,

• then clearly A  C

Additional rules

• If α → β a nd α → γ, then α → β γ (union)

• If α → β γ, then α → β and α → γ (decomposition)

• If α → β and γ β → δ, then α γ → δ

(pseudotransitivity)

The above rules can be inferred from Armstrong’s

axioms.

Example

• R = (A, B, C, G, H, I)
F = { A → B
A → C
CG → H
CG → I
B → H }
  • Some members of F +
    • A → H
      • by transitivity from A → B and B → H
    • AG → I
      • by augmenting A → C with G, to get AG → CG and then transitivity with CG → I
    • CG → HI
      • by augmenting CG → I to infer CG → CG I, and augmenting of CG → H to infer CGI → HI, and then transitivity

Computing the closure for A

• Simple algorithm

• 1. Start with B = A.

• 2. Go over all functional dependencies, β → γ ,

in F +

• 3. If β ⊆ B, then

• Add γ to B

• 4. Repeat till B changes

Example

  • R = (A, B, C, G, H, I) F = { A → B A → C CG → H CG → I B → H }
  • (AG) +^?
  • 1. result = AG
    1. result = ABCG (A → C and A → B)
    2. result = ABCGH (CG → H and CG ⊆ AGBC)
    3. result = ABCGHI (CG → I and CG ⊆ AGBCH

Is (AG) a candidate key?

  1. It is a super key.
  2. (A+) = BC, (G+) = G. Docsity.com

Database Normalization

Functional dependency (FD) means that if

there is only one possible value of Y for every value of X, then

Y is Functionally dependent on X.

Is the following FDs hold?

X −−−−−> Y
X Y Z

10 B1 C

10 B2 C 11 B4 C 12 B3 C 13 B1 C 14 B3 C

X −−−−−> Y
Z −−−−−> Y
Y −−−−−> Z
Y −−−−−> X
  • Functional Dependency is “good”. With functional

dependency the primary key (Attribute A) determines the value of all the other non-key attributes (Attributes B,C,D,etc.)

  • Transitive dependency is “bad”. Transitive dependency

exists if the primary/candidate key (Attribute A) determines non-key Attribute B, and Attribute B determines non-key Attribute C.

  • If a relation schema has more than one key, each is called a

candidate key

  • An attribute in a relation schema R is called prim if it is a

member of some candidate key of R

Database Normalization

1NF

Deptno Dname Location 10 IT Leeds, Bradford, Kent

20 Research Hundredfold 30 Marketing Leeds

Deptno Dname

10 IT 20 Research 30 Marketing

Deptno Location 10 Leeds 10 Bradfprd 10 Kent 20 Hundredfold 30 Leeds

Second Normal Form (2NF)

Each attribute must be functionally dependent on

the primary key.

  • If the primary key is a single attribute, then the relation is in 2NF
  • The test for 2NF involves testing for FDs whose left-hand-side

attribute are part of the primary key

  • Disallow partial dependency, where non-keys attributes depend on

part of a composite primary key

  • In short, remove partial dependencies

2NF improves data integrity.

  • Prevents update, insert, and delete anomalies.

Third Normal Form (3NF)

Remove transitive dependencies.

Transitive dependency

A non-prime attribute is dependent on another, non-prime attribute or attributes Attribute is the result of a calculation

Examples:

Area code attribute based on City attribute of a customer Total price attribute of order entry based on quantity attribute and unit price attribute (calculated value)

Solution:

  • Any transitive dependencies are moved into a smaller table.Docsity.com

Transitive Dependence

Give a relation R ,

Assume the following FD hold:

Note : Both Ename and Address attributes are non-key attributes in R , and since

Address depends on a non-Prime attribute Name, which depends on the primary

key(EmpNo), a transitive dependency exists

EmpNo EName Salary Address

EmpNo − −−−> Ename , Ename −−−−> Addresst , EmpNo −−−−> Address

Ename −−−− > Address

EmpNo EName Salary Ename^ Address

R1 R

Note : If address is a prime attribute Then R is in 3NF