Presentation is loading. Please wait.

Presentation is loading. Please wait.

Normalization Or theoretical and common sense approaches to redesigning a database.

Similar presentations


Presentation on theme: "Normalization Or theoretical and common sense approaches to redesigning a database."— Presentation transcript:

1 Normalization Or theoretical and common sense approaches to redesigning a database

2 References Design principles – Chapter 4 Design of Database Schemas – Chapter 3, specifically the chapters on BCNF and 3 rd normal form. Chapter posted to Canvas.

3 Unnormalized 1 st Normal Form 2 nd Normal Form 3 rd Normal Form BCNF Normal Form 4 th, 5 th Normal Form

4 1NF To be in 1 st Normal Form, a relation must have no multi-valued attributes. Each value must be atomic. See class db. This is bad because it makes it hard to query the values. Atomicity is one of the principles of good database design

5 Decomposition Process of taking a relation and split it into two or more equivalent relations. Must be done losslessly (no loss of data). Solving 1 NF – Remove the key and the non-atomic field and make a new relation keyed on key and the individual key values. – Make multiple fields to hold the non-atomic values (just as bad). – Flatten the table making a row for each individual value.

6 1NF In some references, a Relation violates 1NF if there are repeating groups. See courses in our class db. So the first solution would continue to violate 1NF. It just shifts the problem. But we still have a problem.

7 2NF A relation is in 2NF if it is already in 1NF and it has not partial dependency on the key. – R(A, B, C, D, E, F) – AB -> C, D, E, F – A -> D – B -> E – D and E are only partially dependent on the key.

8 Solving 2NF Remove the partial dependency to a new table. New tables – R(A, B, C, F) – S(A, D) – T(B, E) Note: A table in 1NF that has a single key component is also in 2NF. R(A, B, C, D, E, F) AB -> C, D, E, F A -> D B -> E D and E are only partially dependent on the key.

9 3NF A table is in 3NF if it is in 2NF and it has no transitive dependencies. – R(A, B, C, D, E) – A, B -> C, D, E – D -> E E is transitively dependent on D

10 Solving for 3NF Copy the transitive determinate to a new table and remove the dependent attribute. R(A, B, C, D) S(D, E) R(A, B, C, D, E) A, B -> C, D, E D -> E

11 BCNF A relation R is in BCNF if and only if whenever there is a nontrivial FD {A1, A2, … An} -> {B1, B2, … Bn} for R, it is the case that {A1, A2, … An} is a superkey for R. Often relations that are not in BCNF are also not in 3 rd normal or 2 nd normal form.

12 BCNF Continued A relation in 3NF is not in BCNF if: – The candidate keys are composite keys – there is more than one candidate key in the relation – the keys are not disjoint (in other words, they have some attributes in common). Or to put it another way, all determinants are candidate keys

13 Example From Modern Database Management (Hoffer, Ramesh, Tofi) – SID, Major -> Advisor, MajGPA – Advisor -> Major Anomaly can occur when we need to change the advisor. Not every determinant (advisor) is a superkey to the relation SIDMajorAdvisorMajGPA 123PhysicsHawking4.0 123MusicMahler3.3 456LiteratureMichener3.2 789MusicBach3.7 678PhysicsHawking3.5

14 Decomposition R(SID, Advisor, MajGPA) S(Advisor, Major) Note: if you have to change the advisor, you still have to change it in multiple places.


Download ppt "Normalization Or theoretical and common sense approaches to redesigning a database."

Similar presentations


Ads by Google