Top Banner
Normalisation
25

Normalisation. Un-normalised Form (UNF) Identify an entity List all the attributes Identify a key ORDER(Order Number Order Date Customer Number Customer.

Dec 11, 2015

Download

Documents

Kameron Walline
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Normalisation. Un-normalised Form (UNF) Identify an entity List all the attributes Identify a key ORDER(Order Number Order Date Customer Number Customer.

Normalisation

Page 2: Normalisation. Un-normalised Form (UNF) Identify an entity List all the attributes Identify a key ORDER(Order Number Order Date Customer Number Customer.

Un-normalised Form (UNF)

• Identify an entity

• List all the attributes

• Identify a key

ORDER (Order NumberOrder DateCustomer NumberCustomer NameAddressPost CodeTelephone NumberItem CodeDescriptionUnit CostQuantity)

Page 3: Normalisation. Un-normalised Form (UNF) Identify an entity List all the attributes Identify a key ORDER(Order Number Order Date Customer Number Customer.

Un-normalised Form (UNF)

Identify repeating data items

Page 4: Normalisation. Un-normalised Form (UNF) Identify an entity List all the attributes Identify a key ORDER(Order Number Order Date Customer Number Customer.

Un-normalised Form (UNF)

• Identify repeating data items

ORDER (Order NumberOrder DateCustomer NumberCustomer NameAddressPost CodeTelephone Number

Item CodeDescriptionUnit CostQuantity)

Page 5: Normalisation. Un-normalised Form (UNF) Identify an entity List all the attributes Identify a key ORDER(Order Number Order Date Customer Number Customer.

First Normal Form (1NF)

• Remove repeating data items to form a new entity

• Take the key with you!

ORDER (Order NumberOrder DateCustomer NumberCustomer NameAddressPost CodeTelephone Number

Repeating itemsItem CodeDescriptionUnit CostQuantity)

Page 6: Normalisation. Un-normalised Form (UNF) Identify an entity List all the attributes Identify a key ORDER(Order Number Order Date Customer Number Customer.

First Normal Form (1NF)

• Remove repeating data items to form a new entity

• Take the key with you!

ORDER

ORDER_ITEM

(Order NumberOrder DateCustomer NumberCustomer NameAddressPost CodeTelephone Number)

(Order NumberItem CodeDescriptionUnit CostQuantity)

Page 7: Normalisation. Un-normalised Form (UNF) Identify an entity List all the attributes Identify a key ORDER(Order Number Order Date Customer Number Customer.

First Normal Form (1NF)

• Identify a key for the new entity

• It will be a compound key

• Use the original key and add to it

ORDER

ORDER_ITEM

(Order NumberOrder DateCustomer NumberCustomer NameAddressPost CodeTelephone Number)

(Order NumberItem CodeDescriptionUnit CostQuantity)

Page 8: Normalisation. Un-normalised Form (UNF) Identify an entity List all the attributes Identify a key ORDER(Order Number Order Date Customer Number Customer.

First Normal Form (1NF)

• Identify a key for the new entity

• It will be a compound key

• Use the original key and add to it

• Label the foreign key• Order Number is both

part of the compound primary key and also a foreign key.

ORDER

ORDER_ITEM

(Order NumberOrder DateCustomer NumberCustomer NameAddressPost CodeTelephone Number)

(*Order NumberItem CodeDescriptionUnit CostQuantity)

Page 9: Normalisation. Un-normalised Form (UNF) Identify an entity List all the attributes Identify a key ORDER(Order Number Order Date Customer Number Customer.

First Normal Form (1NF)

• A data model is in 1NF if it has no multi-valued attributes

ORDER

ORDER_ITEM

(Order NumberOrder DateCustomer NumberCustomer NameAddressPost CodeTelephone Number)

(*Order NumberItem CodeDescriptionUnit CostQuantity)

Page 10: Normalisation. Un-normalised Form (UNF) Identify an entity List all the attributes Identify a key ORDER(Order Number Order Date Customer Number Customer.

First Normal Form (1NF)

Page 11: Normalisation. Un-normalised Form (UNF) Identify an entity List all the attributes Identify a key ORDER(Order Number Order Date Customer Number Customer.

First Normal Form (1NF)

But what if there were lots of orders for large deluxe red widgets…?

There are still update anomalies

Page 12: Normalisation. Un-normalised Form (UNF) Identify an entity List all the attributes Identify a key ORDER(Order Number Order Date Customer Number Customer.

Second Normal Form (2NF)

• Examine any entity with a compound key (in this case ORDER_ITEM)

• See if any attributes are dependent on just one part of the compound key

• These are called partial dependencies

ORDER

ORDER_ITEM

(Order NumberOrder DateCustomer NumberCustomer NameAddressPost CodeTelephone Number)

(*Order NumberItem CodeDescriptionUnit CostQuantity)

Page 13: Normalisation. Un-normalised Form (UNF) Identify an entity List all the attributes Identify a key ORDER(Order Number Order Date Customer Number Customer.

Second Normal Form (2NF)

• Order Number is part of the key

• Item Code is part of the key

• Description is dependent on the Item Code

• Unit Cost is dependent on the Item Code

• Quantity is dependent on both Order Number and Item Code.

ORDER

ORDER_ITEM

(Order NumberOrder DateCustomer NumberCustomer NameAddressPost CodeTelephone Number)

(*Order NumberItem CodeDescriptionUnit CostQuantity)

Page 14: Normalisation. Un-normalised Form (UNF) Identify an entity List all the attributes Identify a key ORDER(Order Number Order Date Customer Number Customer.

Second Normal Form (2NF)

• Description and Unit Cost are partial dependencies

• They are dependent on Item Code

• Remove these attributes to a new entity

• Take a copy of the attribute they are dependent on

ORDER

ORDER_ITEM

(Order NumberOrder DateCustomer NumberCustomer NameAddressPost CodeTelephone Number)

(*Order NumberItem CodeDescriptionUnit CostQuantity)

Page 15: Normalisation. Un-normalised Form (UNF) Identify an entity List all the attributes Identify a key ORDER(Order Number Order Date Customer Number Customer.

Second Normal Form (2NF)

• Item Code becomes the key of the new entity

• And becomes a foreign key in ORDER-ITEM

ORDER

ORDER_ITEM

ITEM

(Order NumberOrder DateCustomer NumberCustomer NameAddressPost CodeTelephone Number)

(*Order Number*Item CodeQuantity)

(Item CodeDescriptionUnit Cost)

Page 16: Normalisation. Un-normalised Form (UNF) Identify an entity List all the attributes Identify a key ORDER(Order Number Order Date Customer Number Customer.

Second Normal Form (2NF)

• A data model is in 2NF if it is in 1NF and there are no partial dependencies

ORDER

ORDER_ITEM

ITEM

(Order NumberOrder DateCustomer NumberCustomer NameAddressPost CodeTelephone Number)

(*Order Number*Item CodeQuantity)

(Item CodeDescriptionUnit Cost)

Page 17: Normalisation. Un-normalised Form (UNF) Identify an entity List all the attributes Identify a key ORDER(Order Number Order Date Customer Number Customer.

Second Normal Form (2NF)

• We can add an item to the Item table without it having to be on an order

• We can delete an order in the Order table without deleting details of the items on the order

• We can update item details once in the Item table without affecting the orders for that item in the Order-Item table

Page 18: Normalisation. Un-normalised Form (UNF) Identify an entity List all the attributes Identify a key ORDER(Order Number Order Date Customer Number Customer.

Second Normal Form (2NF)

• But there are still update anomalies with the Order entity

ORDER (Order NumberOrder DateCustomer NumberCustomer NameAddressPost CodeTelephone Number)

Page 19: Normalisation. Un-normalised Form (UNF) Identify an entity List all the attributes Identify a key ORDER(Order Number Order Date Customer Number Customer.

Third Normal Form (3NF)

• Examine all the entities produced so far

• See if there are any non-key attributes which are dependent on any other non-key attributes

• These are called non-key dependencies

ORDER

ORDER_ITEM

ITEM

(Order NumberOrder DateCustomer NumberCustomer NameAddressPost CodeTelephone Number)

(*Order Number*Item CodeQuantity)

(Item CodeDescriptionUnit Cost)

Page 20: Normalisation. Un-normalised Form (UNF) Identify an entity List all the attributes Identify a key ORDER(Order Number Order Date Customer Number Customer.

Third Normal Form (3NF)

• In the ORDER entity, Customer Name, Address, Post Code and Telephone Number are all dependent on Customer Number

ORDER

ORDER_ITEM

ITEM

(Order NumberOrder DateCustomer NumberCustomer NameAddressPost CodeTelephone Number)

(*Order Number*Item CodeQuantity)

(Item CodeDescriptionUnit Cost)

Page 21: Normalisation. Un-normalised Form (UNF) Identify an entity List all the attributes Identify a key ORDER(Order Number Order Date Customer Number Customer.

Third Normal Form (3NF)

• Remove these attributes to a new entity

ORDER

ORDER_ITEM

ITEM

(Order NumberOrder DateCustomer NumberCustomer NameAddressPost CodeTelephone Number)

(*Order Number*Item CodeQuantity)

(Item CodeDescriptionUnit Cost)

Page 22: Normalisation. Un-normalised Form (UNF) Identify an entity List all the attributes Identify a key ORDER(Order Number Order Date Customer Number Customer.

Third Normal Form (3NF)

• Remove these attributes to a new entity

• Customer Number is the key of the new entity

• Leave Customer Number behind as a foreign key

ORDER

CUSTOMER

ORDER_ITEM

ITEM

(Order NumberOrder Date*Customer Number)

(Customer NumberCustomer NameAddressPost CodeTelephone Number)

(*Order Number*Item CodeQuantity)

(Item CodeDescriptionUnit Cost)

Page 23: Normalisation. Un-normalised Form (UNF) Identify an entity List all the attributes Identify a key ORDER(Order Number Order Date Customer Number Customer.

Third Normal Form (3NF)

• A data model is in 3NF if it is in 2NF and there are no non-key dependencies

ORDER

CUSTOMER

ORDER_ITEM

ITEM

(Order NumberOrder Date*Customer Number)

(Customer NumberCustomer NameAddressPost CodeTelephone Number)

(*Order Number*Item CodeQuantity)

(Item CodeDescriptionUnit Cost)

Page 24: Normalisation. Un-normalised Form (UNF) Identify an entity List all the attributes Identify a key ORDER(Order Number Order Date Customer Number Customer.

Third Normal Form (3NF)

• We can add a customer to the Customer table without the customer having to place an order

• We can delete an order in the Order table without deleting details of the customer who placed the order

• We can update a customer’s details once in the Customer table without affecting the orders placed by that customer in the Order table

Page 25: Normalisation. Un-normalised Form (UNF) Identify an entity List all the attributes Identify a key ORDER(Order Number Order Date Customer Number Customer.

Memory Aid

• In 3NF, each attribute is dependent on

• the key

• the whole key

• and nothing but the key