Databases: Normalisation

24,124 views
23,252 views

Published on

Published in: Technology
4 Comments
37 Likes
Statistics
Notes
No Downloads
Views
Total views
24,124
On SlideShare
0
From Embeds
0
Number of Embeds
75
Actions
Shares
0
Downloads
1,813
Comments
4
Likes
37
Embeds 0
No embeds

No notes for slide

Databases: Normalisation

  1. 1. Normalisation
  2. 2. Normalisation <ul><li>Normalisation is a process by which data structures in a relational database are as efficient as possible, including the elimination of redundancy, the minimisation of the use of null values and the prevention of the loss of information. </li></ul>
  3. 3. Aims of Normalisation <ul><li>Normalisation ensures that the database is structured in the best possible way. </li></ul><ul><li>To achieve control over data redundancy. There should be no unnecessary duplication of data in different tables. </li></ul><ul><li>To ensure data consistency. Where duplication is necessary the data is the same. </li></ul><ul><li>To ensure tables have a flexible structure. E.g. number of classes taken or books borrowed should not be limited. </li></ul><ul><li>To allow data in different tables can be used in complex queries. </li></ul>
  4. 4. Duplication vs Redundant Data <ul><li>Duplicated Data: When an attribute has two or more identical values </li></ul><ul><li>Redundant Data: If you can delete data with a loss of information </li></ul>
  5. 5. Stages of Normalisation <ul><li>First Normal Form (1NF) </li></ul><ul><li>Second Normal Form (2NF) </li></ul><ul><li>Third Normal Form (3NF) </li></ul><ul><li>Boyce-Codd Normal Form (BCNF) </li></ul><ul><li>Fourth Normal Form (4NF) </li></ul><ul><li>Fifth Normal Form (5NF) </li></ul>
  6. 7. First Normal Form <ul><li>A table is in its first normal form if it contains no repeating attributes or groups of attributes </li></ul>
  7. 8. Non-Normalised Table STUDENT
  8. 9. First Normal Form <ul><li>To convert data for unnormalised form to 1NF, simply convert any repeated attributes into part of the candidate key </li></ul><ul><li>STUDENT( Number , Name, Classes) </li></ul><ul><li>STUDENT( Number , Name, Classes ) </li></ul>
  9. 10. First Normal Form STUDENT
  10. 11. Over to you...
  11. 12. Second Normal Form A table is in the second normal form if it's in the first normal form AND no column that is not part of the primary key is dependant only a portion of the primary key
  12. 13. Second Normal Form <ul><li>The concept of functional dependency in central to normalisation and, in particular, strongly related to 2NF. </li></ul>
  13. 14. Functional Dependency <ul><li>If ‘X’ is a set of attributes within a relation, then we say ‘A’ (an attribute or set of attributes), is functionally dependant on X, if and only if, for every combination of X, there is only one corresponding value of A </li></ul><ul><li>We write this as : </li></ul><ul><ul><li>X -> A </li></ul></ul>
  14. 15. Table in 1NF
  15. 16. Functional Dependency <ul><li>It is clear that : </li></ul><ul><li>RefNo -> Name, Address, Status </li></ul><ul><li>or, most correctly, </li></ul><ul><li>AccNo, RefNo -> Name, Address, Status </li></ul>
  16. 17. Second Normal Form
  17. 18. Over to you...
  18. 19. Table in Second Normal Form
  19. 20. Third Normal Form A table is in the third normal form if it is the second normal form and there are no non-key columns dependant on other non-key columns that could not act as the primary key.
  20. 21. Table in Second Normal Form
  21. 22. Table in Third Normal Form
  22. 23. Boyce-Codd Normal Form All attributes in a relation should be dependant upon the key, the whole key and nothing but the key
  23. 24. Important Papers <ul><li>E.F.Codd ‘ A Relational Model for Large Shared Data Banks’ CACM 13(6) June 1970 </li></ul><ul><li>E.F. Codd ‘ Extending the Database Relational Model to Capture More Meaning’ ACM Transactions on Database Systems, 4(4), December 1979 </li></ul>
  24. 25. Table in Third Normal Form
  25. 26. Redundancy in 3NF <ul><li>The combination of ROOM, TIME is unique to each tuple, no room is used twice at the same time (thus it is in 3NF). </li></ul><ul><li>But, we know there is a redundancy in that ROOM depends LECTURER, therefore, we split the table... </li></ul>
  26. 27. Tables in BCNF
  27. 28. Difference between BCNF and 3NF <ul><li>Most relations in 3NF are also in BCNF, the only time this may not be true is when there is more than one candidate key for a relation and at least one of is composite. </li></ul>
  28. 29. Fourth Normal Form Fourth normal form (or 4NF) requires that there be no non-trivial multivalued dependencies of attribute sets on something other than a superset of a candidate key. A table is said to be in 4NF if and only if it is in the BCNF and multivalued dependencies are functional dependencies. The 4NF removes unwanted data structures: multivalued dependencies.
  29. 30. Fifth Normal Form Fifth normal form (5NF and also PJ/NF) requires that there are no non-trivial join dependencies that do not follow from the key constraints. A table is said to be in the 5NF if and only if it is in 4NF and every join dependency in it is implied by the candidate keys.
  30. 31. Domain/Key Normal Form Domain/key normal form (or DKNF) requires that the database contains no constraints other than domain constraints and key constraints.

×