4nf 5nf 11

28
BCNF ,4NF n 5NF

Upload: richasharma1977

Post on 21-Apr-2015

177 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: 4NF 5NF 11

BCNF ,4NF n 5NF

Page 2: 4NF 5NF 11

Boyce-Codd Normal Form

BCNF is perhaps the most useful Normal Form for database design

A relation schema R is in BCNF with respect to a set F of functional dependencies if for all functional dependencies in F+ of the form , where R and R, at least one of the following holds:

is trivial (i.e., ) is a superkey for R

Page 3: 4NF 5NF 11

Boyce-Codd Normal Form (BCNF)

• For each FD X->Y,– Rule 1: where Y is in X (Y X) or– Rule 2:where For every FD X-> Y, X has to be a superkey

• Example of BCNF– Customer-schema = (c_name, c_street, c_city)

c_street -> c_street c_city• Is BCNF because of Rule 1

– Loan-schema = (branch_name, c_name, loan_no, amount)• Is not BCNF because Rule 1 or Rule 2 are not satisfied• e.g., Loan_no -> amount, branch_name

– Loan_no cannot be a superkey because wife and husband can create the same Loan_no

Page 4: 4NF 5NF 11

Difference between Two Important Normal Forms

Boyce-Codd Normal Form (BCNF). For every relation scheme R and for every X A that holds over R,

either A X (it is trivial) ,oror X is a superkey for R

Third Normal Form (3NF). For every relation scheme R and for every X A that holds over R,

either A X (it is trivial), or X is a superkey for R, or A is a member of some key for R

Page 5: 4NF 5NF 11

Example of BCNF

fd1 clientNo, interviewDate interviewTime, staffNo, roomNo (Primary Key)fd2 staffNo, interviewDate, interviewTime clientNo (Candidate key)fd3 roomNo, interviewDate, interviewTime clientNo, staffNo (Candidate key)fd4 staffNo, interviewDate roomNo (not a candidate key)

As a consequece the ClientInterview relation may suffer from update anmalies.For example, two tuples have to be updated if the roomNo need be changed for staffNo SG5 on the 13-May-02.

ClientNo interviewDate interviewTime staffNo roomNoCR76 13-May-02 10.30 SG5 G101

CR76 13-May-02 12.00 SG5 G101

CR74 13-May-02 12.00 SG37 G102

CR56 1-Jul-02 10.30 SG5 G102

Figure 8 ClientInterview relation

ClientInterview

Page 6: 4NF 5NF 11

Example of BCNF(2)

To transform the ClientInterview relation to BCNF, we must remove the violating functional dependency by creating two new relations called Interview and SatffRoom as shown below,

Interview (clientNo, interviewDate, interviewTime, staffNo)StaffRoom(staffNo, interviewDate, roomNo)

ClientNo interviewDate interviewTime staffNoCR76 13-May-02 10.30 SG5

CR76 13-May-02 12.00 SG5

CR74 13-May-02 12.00 SG37

CR56 1-Jul-02 10.30 SG5

staffNo interviewDate roomNoSG5 13-May-02 G101

SG37 13-May-02 G102

SG5 1-Jul-02 G102

Interview

StaffRoom

Figure 9 BCNF Interview and StaffRoom relations

Page 7: 4NF 5NF 11

Eliminating Modification Anomalies from Functional Dependencies in Relations

• Put all relations into Boyce-Codd Normal Form (BCNF):

Page 8: 4NF 5NF 11

Putting a Relation into BCNF:EQUIPMENT_REPAIR

Page 9: 4NF 5NF 11

Putting a Relation into BCNF:EQUIPMENT_REPAIR

EQUIPMENT_REPAIR (ItemNumber, Type, AcquisitionCost,RepairNumber, RepairDate, RepairAmount)

ItemNumber (Type, AcquisitionCost)

RepairNumber (ItemNumber, Type, AcquisitionCost, RepairDate, RepairAmount)

ITEM (ItemNumber, Type, AcquisitionCost)

REPAIR (ItemNumber, RepairNumber, RepairDate, RepairAmount)

Where REPAIR.ItemNumber must exist in ITEM.ItemNumber

Page 10: 4NF 5NF 11

Putting a Relation into BCNF:New Relations

Page 11: 4NF 5NF 11

Comparison of BCNF and 3NF

• It is always possible to decompose a relation into relations in 3NF such that:– the decomposition is lossless

– the dependencies are preserved

• It is always possible to decompose a relation into relations in BCNF such that:– the decomposition is lossless

– but it may not be possible to preserve dependencies

Page 12: 4NF 5NF 11

Multivaled Dependencies

• A multivaled dependency occurs when a determinant determines a particular set of values: Employee Degree

Employee Sibling

PartKit Part

• The determinant of a multivaled dependency can never be a primary key

Page 13: 4NF 5NF 11

Multivaled Dependencies

Page 14: 4NF 5NF 11

Eliminating Anomolies from Multivaled Dependencies

• Multivalued dependencies are not a problem if they are in a separate relation, so:– Always put multivaled dependencies into their

own relation– This is known as Fourth Normal Form (4NF)

Page 15: 4NF 5NF 11

Use of Multivalued Dependencies

• We use multivalued dependencies in two ways: 1. To test relations to determine whether they are legal under a

given set of functional and multivalued dependencies2. To specify constraints on the set of legal relations. We shall

thus concern ourselves only with relations that satisfy a given set of functional and multivalued dependencies.

• If a relation r fails to satisfy a given multivalued dependency, we can construct a relations r that does satisfy the multivalued dependency by adding tuples to r.

Page 16: 4NF 5NF 11

Multivalued Dependencies

• There are database schemas in BCNF that do not seem to be sufficiently normalized

• Consider a database

classes(course, teacher, book)such that (c,t,b) classes means that t is qualified to teach c, and b is a required textbook for c

• The database is supposed to list for each course the set of teachers any one of which can be the course’s instructor, and the set of books, all of which are required for the course (no matter who teaches it).

Page 17: 4NF 5NF 11

• There are no non-trivial functional dependencies and therefore the relation is in BCNF

• Insertion anomalies – i.e., if Sara is a new teacher that can teach database, two tuples need to be inserted

(database, Sara, DB Concepts)(database, Sara, Ullman)

course teacher book

databasedatabasedatabasedatabasedatabasedatabaseoperating systemsoperating systemsoperating systemsoperating systems

AviAviHankHankSudarshanSudarshanAviAvi Jim Jim

DB ConceptsUllmanDB ConceptsUllmanDB ConceptsUllmanOS ConceptsShawOS ConceptsShaw

classesMultivalued Dependencies

Page 18: 4NF 5NF 11

• Therefore, it is better to decompose classes into:

course teacher

databasedatabasedatabaseoperating systemsoperating systems

AviHankSudarshanAvi Jim

teaches

course book

databasedatabaseoperating systemsoperating systems

DB ConceptsUllmanOS ConceptsShaw

text

We shall see that these two relations are in Fourth Normal Form (4NF)

Page 19: 4NF 5NF 11

Example of Lossy-Join Decomposition

• Lossy-join decompositions result in information loss.• Example: Decomposition of R = (A, B)

R1 = (A) R2 = (B)

A B

121

A

B

12

rA(r) B(r)

A (r) B (r)A B

1212

Page 20: 4NF 5NF 11

Example • In our example:

course teachercourse book

• The above formal definition is supposed to formalize the notion that given a particular value of Y (course) it has associated with it a set of values of Z (teacher) and a set of values of W (book), and these two sets are in some sense independent of each other.

• Note: – If Y Z then Y Z– Indeed we have (in above notation) Z1 = Z2

The claim follows.

Page 21: 4NF 5NF 11

Fourth Normal Form

• A relation schema R is in 4NF with respect to a set D of functional and multivalued dependencies if for all multivalued dependencies in D+ of the form , where R and R, at least one of the following hold: is trivial (i.e., or = R) is a superkey for schema R

• If a relation is in 4NF it is in BCNF

Page 22: 4NF 5NF 11

Lossy Decompositions

• Not all decompositions are reversible (lossless)

Example:Shipment(S#, P#, J#) decomposed into SP(S#, P#) and SJ(S#, J#)

s1 p1 j1 s1 p1 s1 j1

s2 p2 j1 s2 p2 s2 j1

s2 p3 j2 s2 p3 s2 j2

s3 p3 j3 s3 p3 s3 j3

s4 p4 j3 s4 p4 s4 j3

Page 23: 4NF 5NF 11

Lossy Decompositions

Shipment(S#, P#, J#) decomposed into SP(S#, P#) and SJ(P#, J#)s1 p1 j1 s1 p1 p1 j1s2 p2 j1 s2 p2 p2 j1s2 p3 j2 s2 p3 p3 j2s3 p3 j3 s3 p3 p3 j3s4 p4 j3 s4 p4 p4 j3

If we join SP and SJ again into SP-PJ(S#, P#, P#, J#) we get:s1 p1 p1 j1s2 p2 p2 j1s2 p3 p3 j2 from the joined tuples we cannots2 p3 p3 j3 deduce the original form of the data.s3 p3 p3 j2 this is called the connection traps3 p3 p3 j3 and the decomposition is lossys4 p4 p4 j3

Page 24: 4NF 5NF 11

Fourth Normal Form (4NF)Multi-valued dependency (MVD) represents a dependency between attributes (for example, A, B and C) in a relation, such that for each value of A there is a set of values for B and a set of value for C. However, the set of values for B and C are independent of each other.

A multi-valued dependency can be further defined as being trivial or nontrivial. A MVD A > B in relation R is defined as being trivial if

• B is a subset of A or• A U B = R

A MVD is defined as being nontrivial if neither of the above twoconditions is satisfied.

Page 25: 4NF 5NF 11

Fourth Normal Form (4NF)

Fourth normal form (4NF) A relation that is in Boyce-Codd normal form and containsno nontrivial multi-valued dependencies.

Page 26: 4NF 5NF 11

Fifth Normal Form (5NF)

Lossless-join dependencyA property of decomposition, which ensures that no spurioustuples are generated when relations are reunited through anatural join operation.

Join dependencyDescribes a type of dependency. For example, for a relation R with subsets of the attributes of R denoted as A, B, …, Z, arelation R satisfies a join dependency if, and only if, every legal value of R is equal to the join of its projections on A, B, …, Z.

Fifth normal form (5NF)A relation that has no join dependency.

Page 27: 4NF 5NF 11

Unnormalised (UDF)

First normal form(1NF)

Remove repeating groups

Second normal form(2NF)

Remove partial dependencies

Third normal form(3NF)

Remove transitive dependencies

Boyce-Codd normalform (BCNF)

Remove remaining functional dependency anomalies

Fourth normal form(4NF)

Remove multivalued dependencies

Fifth normal form(5NF)

Remove remaining anomalies

Stages of Normalisation

Page 28: 4NF 5NF 11

• R =(A, B, C, D).• F = {CD, CA, BC}.

• Question 1: Identify all candidate keys for R.

• Question 2: Identify the best normal form that R satisfies.

• Question 3: Decompose R into a set of BCNF relations.

• Question 4: Decompose R into a set of 3NF relations.

Assignment 2 Exercise