270 likes | 380 Views
Normalisation. A Worked Example. Un-normalised form. Write down every data object in the given source materials. Like this. Pick a Primary Key Qu1- What’s this all about?. Decide what the data is all about and underline that data item
E N D
Normalisation A Worked Example
Un-normalised form • Write down every data object in the given source materials.
Pick a Primary KeyQu1- What’s this all about? • Decide what the data is all about and underline that data item • There may be more than one obvious choice - pick any one! • (unlikely in exam?)
Like this… or
Identify repeating groupsQu 2 - How many? • For each <primary key> is there one or more than one of each of the other data items…?
In this case • For each event number is there one or more than one event name? • For each event number is there one or more than one competitor name? …… • For each event number is there one or more than one school name? … Write 1 or M beside each data item
Like this… or
To make it look pretty…put brackets round all the Ms.. This is the repeating group
Write the repeating group as a new tableTake a copy of the primary key with it position competitor_no performance competitor_name school_name school_address1 school_address2 event_no
Decide on a primary key for the new table – decide what this entity is all about (often a compound key here) • position • competitor_no • performance • competitor_name • school_name • school_address1 • school_address2 • event_no Draw a table of sample data to help identify the key attributes
Tidy things up • Write the primary keys at the top of the table • Mark the copy of the original key as a foreign key competitor_no event_no* position performance competitor_name school_name school_address1 school_address2 event_no competitor_no* event_name position performance or
Remove partial dependencies • How? • Examine table with more than 1 key • Draw a grid • Number of rows = number of data items • competitor_no + event_no + position + performance + competitor_name + school_name + school_address1 + school_address2 = 8 • Number of columns = number of keys +2 • competitor_no + event_no + 2 = 4
Qu3 What can be different? • Change one key and fill in data in third column • Mark data which may change • Circle, underline, different colour…
Remove all data items marked in both (all) columns along with copies of the keys Mark the (two) keys as foreign keys
Look at column with ‘Must Change or Maybe’ dataWrite the remaining data items in new list(s) along with marked key in that column
2nd Normal Form Check each table to make sure the key determines all the data items Yes – there is only one Yes – we know from our previous table Better have a closer look at this one!!
Qu4 Does this data describe the key? - yes, it tells us about the competitor yes, it tells us which school the competitor attends no, it tells us about the school no, it tells us about the school
Move to 3NF • Remove non-descriptive items to a new table with the item they describe. Leave a copy of this item as a foreign key