Normalization is a method for organizing data elements in a database into tables.
• Duplication of Data – The same data is listed in multiple lines of the database • Insert Anomaly – A record about an entity cannot be inserted into the table without first inserting information about another entity – Cannot enter a customer without a sales order • Delete Anomaly – A record cannot be deleted without deleting a record about a related entity. Cannot delete a sales order without deleting all of the customer’s information. • Update Anomaly – Cannot update information without changing information in many places. To update customer information, it must be updated for each sales order the customer has placed
Normalization is a three stage process – After the first stage, the data is said to be in first normal form, after the second, it is in second normal form, after the third, it is in third normal form
1. Begin with a list of all of the fields that must appear in the database. Think of this as one big table. 2. Do not include computed fields
3. One place to begin getting this information is from a printed document used by the system. 4. Additional attributes besides those for the entities described on the document can be added to the database.
Before Normalization – Example
See Sales Order from below:
Fields in the original data table will be as follows:
|SalesOrderNo |Date |CustomerNo |Custom|CustomerAdd | | | | |erName| | | | | | | | | | | | | |
The repeating fields will be removed from the original data table, leaving the following. |SalesOrderNo |Date |CustomerNo |CustomerName |CustomerAdd |ClerkNo |ClerkName | | | | | | | | |
These two tables are a database in first normal form
What if we did not Normalize the Database to First Normal Form?
Repetition of Data – SO Header data repeated for every line in sales order.
Normalization: Second Normal Form
• Remove Partial Dependencies.
• Functional Dependency The value of one attribute in a table is determined entirely by the value of another. • Partial Dependency A type of functional dependency where an attribute is functionally dependent on only part of the primary key (primary key must be a composite key). • Create separate table with the functionally dependent data and the part of the key on which it depends. Tables created at this step will usually contain descriptions of resources.
Second Normal Form Example
The new table will contain the following fields:
|ItemNo |Description |
| | |
| | |
All of these fields except the primary key will be removed from the original table. The primary key will be left in the original table to allow linking of data: |SalesOrderNo |ItemNo |Qty |UnitPrice |
| | | | | | | | | |
Never treat price as dependent on item. Price may be different for different sales orders (discounts, special customers, etc.) Along with the unchanged table below, these tables make up a database in second normal form: |SalesOrderNo |Date |CustomerNo |CustomerName |CustomerAdd |ClerkNo |ClerkName | | | | | | | | |
What if we did not Normalize the Database to Second Normal Form?