Saturday, August 11, 2007

Normalization and Denormalization



1st Normal Form (1NF) — Eliminate repeating groups, such that all records in all tables can be identified uniquely by a primary key in each table. In other words, all fields other than the primary key must depend on the primary key.
1NF the Easy Way
Remove repeating fields by creating a new table where the original and new table, are linked together, with a master-detail, one-to-many relationship. Create primary keys on both tables where the detail table will have a composite primary key, containing the master table primary key field as the prefix field, of its primary key. That prefix field is also a foreign key back to the master table.
2nd Normal Form (2NF) — All non-key values must be fully functionally dependent on the primary key. No partial dependencies are allowed. A partial dependency exists when a field is fully dependent on a part of a composite primary key. A composite primary key is a primary key of more than one field.
2NF the Easy Way
Perform a seemingly similar function to that of 1NF, but create a table where repeating values, rather than repeating fields, are removed to a new table. The result is a many-to-one relationship, rather than a one-to-many relationship, created between the original and new tables. The new table gets a primary key consisting of a single field. The master table contains a foreign key pointing back to the primary key of the new table. That foreign key is not part of the primary key in the original table.
3rd Normal Form (3NF) — Eliminate transitive dependencies. What this means is that a field is indirectly determined by the primary key. This is because the field is functionally dependent on an intermediary field, where the intermediary field is dependent on the primary key.
3NF the Easy Way
It is difficult to explain 3NF without using a mind-bogglingly, confusing, technical definition. Elimination of a transitive dependency implies creation of a new table, for something indirectly dependent on the primary key, in an existing table. There are a multitude of ways in which 3NF can be interpreted.


No comments: