Database Design (Normalizations)
DCO11310
Database Systems and Design
By Rose Chang
Logical Data Model
1. Build a Conceptual Data Model2. Build and validate logical data model (LDM)
Drive relations for LDM Validate relations using normalisation Validate relations against user transactions Check integrity constraints Review LDM with user Merge LDMs into global model
Top-down Modeling
Entity - Entity - Entity
DATABASE
Table - Table – Table - Table - Table
Attributes+
Constraints
Attributes+
Constraints
Attributes+
Constraints
Attributes+
Constraints
Attributes+
Constraints
Bottom-up Modeling
Entity - Entity - Entity
DATABASE
Table - Table – Table - Table - Table
Attributes+
Constraints
Attributes+
Constraints
Attributes+
Constraints
Attributes+
Constraints
Attributes+
Constraints
Normalizations
A process that assigns attributes to entities in such a way that data redundancies are reduced or eliminated
Enables us to analyse the design of the database Identify the existence of potential data anomalies result from
those redundancies A step to step process : given a data model and the relevant
FDs Decomposition of relation schema based on knowledge of
underlying functional dependencies Results in a relational schema that satisfies certain important criteria:
1NF, 2NF, 3NF, BCNF, 4NF, … E.G., No anomalies, no spurious or invalid data during joins
Update Anomalies
Redundancies Information fact is stored in more than one place
Insertion anomalies Unable to insert a fact into table without having other facts (or
inserting nulls) Deletion anomalies
If a set of values becomes empty, we may lose other information as a side effect
Modification anomalies Change the information in one tuple but leave information
unchanged in another
Example
Real bad design: Study(Sid,name,Dept,Course_code, Course_name)
Sid Name Dept C_code C_Name
S01 Rose DCO 20401 DB
S01 Rose DCO 30198 Project
S02 Peter DCO 20401 DB
S03 Mary DCO 30198 Project
S04 Tom DCO 20401 DB
What are the Anomalies?
Redundancy Insertion Anomaly Deletion Anomaly What is the best design for this information?
No anomalies Can reconstruct all original information
Process of Normalization
Users User’s requirement
Forms/ Report
Other sourcesFrom company
Data sources
UNFTransfer attributes into table format
1NFRemove repeating group
2NF
Remove partial dependencies
3NFRemove transitive dependencies
Normalizations
Unnormalised Form (UNF) can be captured from data entities generated in System Analysis phase sample reports or screens
Invoice
Stf_name: Rose C W Chang Stf_ID. : 50121456Dept: Sales Dpt_Code: SAL
Item Code Item Description PriceI011 Wing-Type-A 70I012 Wing-Type-B 60I013 Engine-Type-A 70
Total 200
First Normal Form
A relation is in first normal form (1NF) if and only if All the key attributes are defined There are no repeating groups in the table All non-primary-key attribute is functionally
dependent on the primary key Problem : attributes not necessary fully
functionally dependent
Functional Dependencies
Attribute B is functionally dependent on attribute A if and only if each value of A is associated with precisely one value of B at any one time
E.G. Stf_name is functionally dependent on Stf_ID, Stf_ID Stf_name
The attribute on the left is a determinant
First Normal Form (1NF)
Eliminate repeating groups of data items
UNF 1NFStf_ID Stf_IDStf_name Stf_nameDept_code Dept_codeDept_name Dept_name{Item_code Item_desc Stf_ID Price } Item_code Item_desc
Price
Second Normal Form
A relation is in second normal form (2NF) if and only if It is in 1NF All non-primary-key attribute is fully
functionally dependent on the primary key, that is, there is no partial dependecy.
Full Functional Dependency
Attribute B is fully functionally dependent (FD) on attribute A if it is functionally dependent on A and NOT functionally dependent on any subset of A
All determinants in each relation are candidate keys
1NF 2NFStf_ID Stf_IDStf_name Stf_nameDept_code Dept_codeDept_name Dept_name
Stf_ID Stf_ID Item_codeItem_code Item_code Item_descItem_desc Price Price
Second Normal Form (2NF)
Record is in 1NF and no partly dependencies
Third Normal Form
A relation is in third normal form (3NF) if and only if It is in 2NF It contains NO transitive dependencies
transitive dependencies A condition where A, B, and C are attributes of a relation
such that if AB and BC, then C is transitively dependent on A via B (provided that A is not FD on B or C)
Third Normal Form (3NF)
Record is in 2NF and no transitive dependencies (no fields dependent on nonkey field(s))
2NF 3NFStf_ID Stf_ID Dept_codeStf_name Stf_name Dept_nameDept_code Dept_codeDept_name
Stf_ID Item_codeStf_ID Item_code Item_code Item_descItem_code Item_desc PricePrice
E/R Model after Normalization
Staff Sold Items
ItemDept
Normalize it to 3NF
Wellmeadows Hospital
Drug
Ward 11
Units per
Robert MacDonald
Orthopaedic
Name
10223 Morphine Pain Killer
Ward Number :
Ward Name :
Full Name :
P10034 Patient Number :
Patient Medication Form
84 Bed Number :
Dosage Description
10mg/ml 50
Number Day
Start
24/03/96
Date
Finish
24/04/96
Date
10334 Tetracyclene Antibiotic 0.5mg/ml 10 24/03/96 17/04/96
10223 Morphine Pain Killer 10mg/ml 10 25/04/96 02/05/96
Method
Admin
Oral
IV
Oral
of
Q & A
Readings:Connolly: Ch13, except BCNF, 4NF & 5NF