Normalisation up to 1NF Bottom-up Approach to Data Modelling.

21
Normalisation up to 1NF • Bottom-up Approach to Data Modelling
  • date post

    21-Dec-2015
  • Category

    Documents

  • view

    221
  • download

    0

Transcript of Normalisation up to 1NF Bottom-up Approach to Data Modelling.

Normalisation up to 1NF

• Bottom-up Approach to Data Modelling

Objectives

• Define the purpose of normalisation

• Determinacy / Dependency

• First Normal Form

• Second Normal Form

• Third Normal Form

10

Normalisation

• Normalisation provides algorithms for reducing complex data structures into simple data structures

• Concerned with –tidying up the data so there is no data redundancy–ensuring that data is grouped logically

• Bottom up approach - start with data items• Codd’s Law is a set of rules which ensure that

the data is grouped correctly–A normal form is a convenient structure into which

data can be organised

A relation is relational…

If and only if every non-key attribute

is determined by

the KEY…

the WHOLE KEY….

and nothing but the KEY

so help me CODD!

Dr. E.F. Codd, an IBM researcher, first developed the relational data model in 1970

Concept of Determinacy and Dependency

• if A determines B - then B is dependent on A

• B is dependent on A if given a value for A, there is only one possible value for B– e.g. – student name is dependent on student number

and– student number determines student name

12

First Normal Form (1NF)– an form is in 1NF if and only if it has an identifying

key and there are no repeating groups of attributes

• To do1. Find the key to the original form

2. remove calculated (derived) fields from the original form

3. move repeating attributes into a new form– These are generally column headings in a grid.

4. Add the key to the original form as a foreign key to the new form

5. Determine the key to the new form

• Result: 1NF forms

Second Normal Form (2NF)

• a form is in 2NF if and only if it is in 1NF and has no attributes which require only part of the key to uniquely identify them

• To do - remove part-key dependencies:1. where a key has more than one attribute, check that each

non-key attribute depends on the whole key and not part of the key

2. for each subset of the key which determines an attribute or group of attributes create a new form. Move the dependant attributes to the new form.

3. Add the part key to new form, making it the primary key.4. Mark the part key as a foreign key in the original form.

• Result: 2NF forms

Third Normal Form (3NF)

– an form is in 3NF if and only if it is in 2NF and no non-key attribute depends on any other non key attribute

• To do - remove non key dependencies:1. decide on the direction of the dependency2. if A depends on B create new form. Copy B to it as

the primary key and move A as attribute(s)3. leave B in original form, mark it as a foreign key.

• A and B can be groups of attributes

• Result: 3NF forms

Representing Normal Forms Graphically

• If primary key of form A is a subset of the primary key of form B, then the relationship of A to B is one to many

• If P contains foreign key F and F is the primary key of Q, then the relationship of P to Q is many to one

• Use form and relationship notation as before

Two Technique Approach to Data Modelling

• E-R diagramming to find and group all data items

• normalisation to ensure data items are grouped correctly

Joe’s Docket

“I f you can’t find it, go to J oe!”

J oe’s Builders’ Supplies (01) 8437083 Main St., Malmont, D27.

Docket No: 196

Stock code. Quantity Description Unit Price VAT (20%)

Total Price

A642 4 4”x4” treated timber £9.50 £1.30 £43.20

J555 1 Box of 6” phillips screws (100)

£5.00 £1.00 £6.00

J501 1 Phillips head screwdriver £8.00 £1.60 £9.60

Total Amount Due: £58.80

Docket paid signature_J oe Bloggs (Staff)

Staff No: 124 Staff Name J oe Bloggs Staff Role: Yard foreman

Items received signature__Andy Handy__(Customer)

Before we begin…

• We have already discussed– Entities– Attributes– Values– Data and Metadata

• We now take one of the documents and apply:– Unnormalised form rules (Data Dictionary format)– First Normal Form rules– Second Normal Form rules– Third Normal Form rules

Data Dictionary

– central store of data that supports other models– unambiguous and concise way of recording data about

data (metadata)– can be recorded manually or using a software tool– encourages consistency between models by using

same names in different models– prevents duplication of data– resolves problems of aliases which are all recorded

against the appropriate data item– built up as the models are developed– aids communication as everyone on development team

knows the exact meaning of words and terms used

Sequence, selection, iteration

• Sequence : +– CustomerDetails = Name + Address + PhoneNo

• Repetition : { }– Name = Title + {Initial} + Surname

• Optionality : ( )– CustomerDetails = Name + Address +(PhoneNo)

• Selection : […|…]– Name = (Title) + [ {ForeName} | {Initial} ] +

Surname

• Values : “…”– Title = [ “Dr” | “Mr” | “Mrs” | “Ms” ]

• Comments : *….*

4

Example

• Full data dictionary entries for CustomerDetailsAddress = {AddressLine}

CustomerDetails = Name + Address + (PhoneNo)

Name = (Title) + [ {ForeName} | {Initial} ] +Surname

Title = [ “Dr” | “Mr” | “Mrs” | “Ms” ]

Our Docket again…

“I f you can’t find it, go to J oe!”

J oe’s Builders’ Supplies (01) 8437083 Main St., Malmont, D27.

Docket No: 196

Stock code. Quantity Description Unit Price VAT (20%)

Total Price

A642 4 4”x4” treated timber £9.50 £1.30 £43.20

J555 1 Box of 6” phillips screws (100)

£5.00 £1.00 £6.00

J501 1 Phillips head screwdriver £8.00 £1.60 £9.60

Total Amount Due: £58.80

Docket paid signature_J oe Bloggs (Staff)

Staff No: 124 Staff Name J oe Bloggs Staff Role: Yard foreman

Items received signature__Andy Handy__(Customer)

Making the Docket logical

• Many of the names on the docket are local to Joe’s business.

• We try to make them more standard, so– A Docket becomes a Customer Order or COrder.

• There are three signatures on the Docket. Signatures by their nature are manual. In a computerised system, these will be replaced by an authorisation procedure, which will show – which staff member – their number will do - took payment

(StaffPaid) and – which staff member marked the items as received (StaffIssued). – The customer name is also kept on record.

Data Dictionary Definition of the Docket

• Unnormalised data– COrder = COrderNo + {Stock_Code +

QuantityRequired +(StockDescription) + UnitPrice + 20%VAT + TotalPrice} + TotalAmtDue + StaffPaid +StaffIssued + StaffName + StaffRole + customer_name

12

Remember (1NF)

• To do1. Find the key to the original form

2. remove calculated (derived) fields from the original form

3. move repeating attributes into a new form

4. Add the key to the original form as a foreign key to the new form

5. Determine the key to the new form

• Result: Forms in First Normal Form

Normalising…• Find the key to the original form:

– The COrderNo uniquely defines the COrder

• Remove calculated (derived) fields:– TotalPrice, 20%VAT and TotalAmtDue are derived

fields. Each can be calculated from other data on the form.

– COrder = COrderNo + {Stock_Code + QuantityRequired +(StockDescription) + UnitPrice} + StaffPaid +StaffIssued + StaffName + StaffRole + Customer_Name

…Normalising…

• move repeating attributes into a new form– Original form COrder = COrderNo + StaffPaid + StaffIssued +

StaffName + StaffRole + Customer_Name– New form COrderLine = Stock_Code + QuantityRequired +

(StockDescription) + UnitPrice– Add the key to the original form as a foreign key to the

new form– New form COrderLine = Stock_Code + QuantityRequired +

(StockDescription) + UnitPrice + COrderNo*– Determine the key to the new form

• COrderLine = Stock_Code+COrderNo* + StockDescription + UnitPrice + QuantityRequired