databases – attributes & entities normalisation

13
ICT@ WJEC Applied IC Databases – Attributes & Entities Normalisation It is important in Database Design to make sure that the correct attributes are grouped into the correct tables. Normalisation is a process that allows us to do this. This reduces the duplication of data and helps stop inconsistencies. Normalisation is done in three phases – 1NF, 2NF and 3NF. These are as follows 1) 1NF – Atomic Data Test 2) 2NF – Partial key dependence test 3) 3NF – Non-key dependence test

Upload: zavad

Post on 23-Feb-2016

33 views

Category:

Documents


0 download

DESCRIPTION

Databases – Attributes & Entities Normalisation It is important in Database Design to make sure that the correct attributes are grouped into the correct tables. Normalisation is a process that allows us to do this. This reduces the duplication of data and helps stop inconsistencies. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Databases – Attributes & Entities Normalisation

ICT@WJEC Applied ICT

Databases – Attributes & Entities

NormalisationIt is important in Database Design to make sure that the correct attributes are grouped into the correct tables. Normalisation is a process that allows us to do this. This reduces the duplication of data and helps stop inconsistencies.

Normalisation is done in three phases – 1NF, 2NF and 3NF. These are as follows

1) 1NF – Atomic Data Test

2) 2NF – Partial key dependence test

3) 3NF – Non-key dependence test

Page 2: Databases – Attributes & Entities Normalisation

ICT@WJEC Applied ICT

Databases – Attributes & Entities

NormalisationConsider this table:

There are multiple entries for some of the attributes. How much space should we leave for these. These attributes are said to be “repeating groups” or non-atomic data. Lets remove them to another table.

Order Number

Customer ID

Delivery Address

Email Address

Order Date

Item Code

Desc Order Quantity

Unit Price

012367 BLF1 Fred Bloggs 1 High Street, Any town

[email protected]

01/05/09

1234 Ring Binder

3 1.50

8967 Divider 4 0.50

3456 Stapler 1 2.99

034231 SMJ2 Joe Smith7, The Lane, Anytown

[email protected]

03/05/09

9684 Scissors 2 1.99

3456 Stapler 4 2.99

Page 3: Databases – Attributes & Entities Normalisation

ICT@WJEC Applied ICT

Databases – Attributes & Entities

NormalisationTable 1 in 1NF

Order Number

Customer ID

Delivery Address

Email Address

Order Date

012367 BLF1 Fred Bloggs 1 High Street, Any town

[email protected]

01/05/09

034231 SMJ2 Joe Smith7, The Lane, Anytown

[email protected]

03/05/09

Page 4: Databases – Attributes & Entities Normalisation

ICT@WJEC Applied ICT

Databases – Attributes & Entities

NormalisationTable 2 in 1NF

Order number and Item code make a composite key.

OrderNumber

Item Code Desc Order Quantity

Unit Price

012367 1234 Ring Binder 3 1.50

012367 8967 Divider 4 0.50

012367 3456 Stapler 1 2.99

034231 9684 Scissors 2 1.99

034231 3456 Stapler 4 2.99

Page 5: Databases – Attributes & Entities Normalisation

ICT@WJEC Applied ICT

Databases – Attributes & Entities

NormalisationWhich of these tables are NOT in first normal form?

Page 6: Databases – Attributes & Entities Normalisation

ICT@WJEC Applied ICT

Databases – Attributes & Entities

NormalisationMoving to 2NF

The item details are only dependant on the item code which is part of the key and not the OrderNumber as well. This also means we only store details of the items when we order them. To make it 2NF all the attributes must be dependant on the full key.

We create another table for the items.

OrderNumber

Item Code Desc Order Quantity

Unit Price

012367 1234 Ring Binder 3 1.50

012367 8967 Divider 4 0.50

012367 3456 Stapler 1 2.99

034231 9684 Scissors 2 1.99

034231 3456 Stapler 4 2.99

Page 7: Databases – Attributes & Entities Normalisation

ICT@WJEC Applied ICT

Databases – Attributes & Entities

NormalisationTable 1 in 2NF

Order Number

Customer ID

Delivery Address

Email Address

Order Date

012367 BLF1 Fred Bloggs 1 High Street, Any town

[email protected]

01/05/09

034231 SMJ2 Joe Smith7, The Lane, Anytown

[email protected]

03/05/09

Page 8: Databases – Attributes & Entities Normalisation

ICT@WJEC Applied ICT

Databases – Attributes & Entities

NormalisationTable 2 in 2NF

OrderNumber

Item Code Order Quantity

012367 1234 3

012367 8967 4

012367 3456 1

034231 9684 2

034231 3456 4

Page 9: Databases – Attributes & Entities Normalisation

ICT@WJEC Applied ICT

Databases – Attributes & Entities

NormalisationTable 3 in 2NF

Item Code Desc Unit Price1234 Ring Binder 1.50

8967 Divider 0.50

3456 Stapler 2.99

9684 Scissors 1.99

3456 Stapler 2.99

Page 10: Databases – Attributes & Entities Normalisation

ICT@WJEC Applied ICT

Databases – Attributes & Entities

NormalisationMoving to 3NF

If we go back to first table - Order Number

Customer ID

Delivery Address

Email Address

Order Date

012367 BLF1 Fred Bloggs 1 High Street, Any town

[email protected]

01/05/09

034231 SMJ2 Joe Smith7, The Lane, Anytown

[email protected]

03/05/09

The primary key here is the OrderNumber. However the Delivery Address and Email Address is dependant on the Customer ID. So this table is not in Third Normal Form (3NF) because it fails the non-key dependance test. So we must create a new table for the customer information.

Page 11: Databases – Attributes & Entities Normalisation

ICT@WJEC Applied ICT

Databases – Attributes & Entities

NormalisationLet us have a look at our 4 tables now in 3NF.

Table : OnlineOrder

Order Number

Customer ID

Order Date

012367 BLF1 01/05/09

034231 SMJ2 03/05/09

Table: Customer

Customer ID

Delivery Address

Email Address

BLF1 Fred Bloggs 1 High Street, Any town

[email protected]

SMJ2 Joe Smith7, The Lane, Anytown

[email protected]

Page 12: Databases – Attributes & Entities Normalisation

ICT@WJEC Applied ICT

Databases – Attributes & Entities

NormalisationLet us have a look at our 4 tables now in 3NF.

Table: ItemOrderOrderNumber

Item Code Order Quantity

012367 1234 3

012367 8967 4

012367 3456 1

034231 9684 2

034231 3456 4

Table: ItemItem Code Desc Unit Price1234 Ring Binder 1.50

8967 Divider 0.50

3456 Stapler 2.99

9684 Scissors 1.99

3456 Stapler 2.99

Page 13: Databases – Attributes & Entities Normalisation

ICT@WJEC Applied ICT

Databases – Attributes & Entities

Normalisation

Tasks

1) Can you write the new tables in Database notation?2) Can you create an Entity Relationship Diagram for the new

Customer Order System?3) Have a go at the scenarios below. Can you put the following flat files

into 3NF.

CAR (Make, Model, Name of part, Price, Supplier name, supplier telephone number, Supplier Address)

RACES (Race name, venue, start point, end point, miles, runner name, time to finish, club name, club address, club telephone number)

Runners only belong to one club.