Post: Drimnagh, Dublin 12, Republic Of Ireland

Tel/Fax: 353-1-4548335 Email:dbassist@indigo.ie

Normalisation

<<< back to Access Tips

   (This page is worth printing and reading with a cup of tea!)

When designing a database you are faced wth a number of questions: How many tables will there be? What will they represent? Which columns (fields) will go in which tables? This page is intended to make the answers to these questions easier if not automatic.

There's never enough time to do it right first time, but always enough time to do it over?

Trial and error may get you there, but may also get you certifiable. Frustrations, confusions and anxieties can be eliminated with good planning. One valuable (if not indespensible) planning tool for designing databases is called Normalisation.

Normalisation is the process of simplyfying the design of a database so that it achieves optimum structure. It implements a theory called Normal Forms - a linear progression of rules you apply - with each higher 'normal form' acheiving a better more efficient design. This page will bring you as far as the Third Normal Form - there are more, but if you apply these three you are well on your way.

First Normal Form (1NF) - All column values must be atomic

These means that in your table, for every row-by-column position (cell), there exists only one value - not an array or list of values:

OrderID CustID Date Items
1 4 4/11/02 5 Hammers, 3 Screwdrivers, 6 Monkey Wrench
2 23 6/11/02 1 Hammer
3 15 7/11/02 2 Delux Garden Hose, 2 Economy Nozzle
4 2 7/11/02 15 10" 2x4 Untreated Pine Board
5 23 7/11/02 1 Screwdriver
6 2 8/11/02 5 Key

tblOrders violates 1NF because data stored in the [items] field is not atomic

1NF also prohibits the presence of repeating groups, even if they are stored in multiple columns:

OrderID CustID Date Qty1 Item1 Qty2 Item2 Qty3 Item3
1 4 4/11/02 5 Hammer 3 Screwdriver 6 Monkey Wrench
2 23 6/11/02 1 Hammer        
3 15 7/11/02 2 Delux Garden Hose 2 Economy Nozzle    
4 2 7/11/02 15 10" 2x4 Untreated Pine Board        
5 23 7/11/02 1 Screwdriver        
6 2 8/11/02 5 Key        

A better but still flawed version of the tblOrders table. The repeating 
groups of information violate 'First Normal Form'

To attain 1NF, we have added a column [OrderItemID]. Now, the primary key of the table is the composite of [OrderID] and [OrderItemID]

OrderID OrderItemID CustID Date Qty Item
1 1 4 4/11/02 5 Hammer
1 2 4 4/11/02 3 Screwdriver
1 3 4 4/11/02 6 Monkey Wrench
2 1 23 6/11/02 1 Hammer
3 1 15 7/11/02 2 Delux Garden Hose
3 2 15 7/11/02 2 Economy Nozzle
4 1 2 7/11/02 15 10" 2x4 Untreated Pine Board
5 1 23 7/11/02 1 Screwdriver
6 1 2 8/11/02 5 Key

This table is now in 1NF because each column value is atomic and 
there are no repeating groups

Second Normal Form (2NF) is already in 1NF and each non-key column is fully dependent on the (entire) Primary Key

This is saying that tables should only store data relating to one 'thing' and should be fully described by it's primary key. 

In our example above, the primary key is the composite of  [OrderID] and [OrderItemID], so, does this (combined) value for a given record imply the value of every other column in that record? No it doesn't - given the value of just the [OrderID] field, you know the customer and the date, without having to know the [OrderItemID]. So neither the [CustID] field nor the [Date] field is dependent on the (entire) primary key.

We can acheive 2NF by breaking our table out into two separate tables.  We put everything that applies to each Order in one table and everything that applies to each Order Detail in a second table. This is called decomposition.

OrderID CustID Date
1 1 4/11/02
2 3 6/11/02
3 1 7/11/02
4 2 7/11/02
5 1 7/11/02
6 2 8/11/02

tblOrders

We decompose these tables in such a way as to allow us to put them back together using queries.

Thus it is important to make sure that tblOrderDetails containsa foreign key a to tblOrders.

The foreign key in this case is the [OrderID] field which appears in both tables.

 

OrderDetailD OrderID Qty ItemID Item
1 1 5 32 Hammer
2 1 3 2 Screwdriver
3 1 6 40 Monkey Wrench
1 2 1 32 Hammer
1 3 2 113 Delux Garden Hose
2 3 2 121 Economy Nozzle
1 4 15 1024 10" 2x4 Untreated Pine Board
1 5 1 2 Screwdriver
1 6 5 52 Key

tblOrderDetails

Third Normal Form (3NF) is already in 2NF and all non-key columns are mutually independent.

In our example here, tblOrderDetails is in 2NF because all its non-key columns are fully dependent on the primary key. However, the table also contains a dependency between two of its non-key columns: [ItemID] and [Item].

Suppose you need to add 150 detail records, each involving the purchase of screwdrivers. You will have to input an [ItemID] of '2' and an [Item] of 'Screwdriver' for each of these 150 records. Similarly, if you decided to change the description of item to "No. 2 Philips-head Screwdriver", you will have to locate and update every singly record in your database.

This is where 3NF comes in handy. You further decompose the table by breaking out the [ItemID] and [Item] dependency. This changes the tblOrderDetails and reates a new table called tblItems

Again, when composing, take care to put a linking column in both tables. In our case, the [ItemID] field becomes the primary key of the new table tblItems and the foreign key in the tblOrderDetails

ItemID Item
2 Screwdriver
32 Hammer
40 Monkey Wrench
52 Key
113 Delux Garden Hose
121 Economy Nozzle
1024 10" 2x4 Untreated Pine Board

tblItems

Both these tables are in Third Normal Form (3NF)

The [ItemID] column is the primary key in the table tblItems and is now the foreign key in tblOrderDetails

OrderID OrderDetailID Qty ItemID
1 1 5 32
1 2 3 2
1 3 6 40
2 1 1 32
3 1 2 113
3 2 2 121
4 1 15 1024
5 1 1 2
6 1 5 52

tblOrderDetails

We now have three well designed tables (instead of one badly designed one) that are easily linked with relationships and are easily maintained. We've eliminated data redundancy and avoided any inconsistent dependancy. (We've also had to cope with a few unusual terms - check out  Access glossary of words & terms )


 

Home ] Development ] Training ] Access Tips ] Excel Tips ] Philosophy ] Take A Break ]

Send mail to dbassist@indigo.ie with questions or comments about this web site.
Copyright © 2002 DBAssist
Last modified: November 03, 2002