Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "Normalisation up to 1NF Bottom-up Approach to Data Modelling."— Presentation transcript:

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

2 Objectives Define the purpose of normalisation Determinacy / Dependency First Normal Form Second Normal Form Third Normal Form

3 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

4 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

5 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 do 1.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: 1NF forms

6 Second Normal Form (2NF) an 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

7 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 dependency 2.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

8 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

9 Joe’s Docket

10 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 : *….*

11 Our Docket again…

12 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.

13 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

14 12 Remember (1NF) To do 1.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

15 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

16 …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

17 The following forms: COrder COrderNo StaffPaid StaffIssued StaffName StaffRole Customer_Name COrderLine StockCode *COrderNo StockDescription UnitPrice QuantityRequired

18 Second Normal Form 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. This rule only applies if the form has a compound key (i.e. more than one attribute in the key) –The COrder form is not affected by the 2NF rule. –The COrderLine has a compound key of Stock_Code + COrderNo*

19 Normalising... 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 –Stock description and UnitPrice are determined by the Stock_Code

20 …Normalising 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. COrderLine = Stock_Code+COrderNo* +StockDescription + UnitPrice + QuantityRequired Remove StockDescription and UnitPrice to a new form called Stock. Stock = StockDescription + UnitPrice

21 …Normalising… 3.Add the part key to new form, making it the primary key. Stock = Stock_Code + StockDescription + UnitPrice 4.Mark the part key as a foreign key in the original form. –COrderLine = Stock_Code*+COrderNo* + QuantityRequired

22 Second Normal Form Stock = Stock_Code + StockDescription + UnitPrice COrderLine = Stock_Code*+COrderNo* + QuantityRequired –And the unchanged form: COrder = COrderNo + StaffPaid + StaffIssued + StaffName + StaffRole + Customer_Name

23 Resulting forms COrder COrderNo StaffPaid StaffIssued StaffName StaffRole CustomerName COrderLine *COrderNo *StockCode QuantityRequired Stock StockCode StockDescription UnitPrice

24 Third Normal Form Remove any fields that are transitively dependent on the key: To do - remove non key dependencies: 1.decide on the direction of the dependency 2.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 and remove A A and B can be groups of attributes

25 Normalising… COrder = COrderNo + StaffPaid +StaffIssued + StaffName + StaffRole + Customer_name 1.decide on the direction of the dependency –The StaffName and StaffRole are dependent only on the the StaffIssued, not on the COrderNo 2.if A depends on B create new form. Copy B to it as the primary key and move A as attribute(s) –Staff = StaffIssued + StaffName + StaffRole 3.leave B in original form, mark it as a foreign key and remove A –COrder = COrderNo + StaffPaid + StaffIssued* + Customer_Name

26 Resulting Forms COrder DocketNo StaffPaid *StaffIssued * Customer_Name COrderLine *COrderNo *StockCode QuantityRequired Stock StockCode StockDescription UnitPrice Staff StaffIssued StaffName StaffRole


Download ppt "Normalisation up to 1NF Bottom-up Approach to Data Modelling."

Similar presentations


Ads by Google