Normalization of Database Models
Normalization of Database Models
What normalization is and what role it plays in database design About the normal forms 1NF, 2NF, 3NF, BCNF, and 4NF How normal forms can be transformed from lower normal forms to higher normal forms
That normalization and E-R modeling are used concurrently to produce a good database design That some situations require denormalization to generate information efficiently
Table is basic building block in database design Tables structure is of great interest Two cases:
possible poor table structures in good database design Modify existing database with existing poor table structure
Normalization can help recognize a poor table and convert to good tables with good structure
4
Normalization stages
1NF - First normal form 2NF - Second normal form 3NF - Third normal form 4NF - Fourth normal form
Better in dependency
Building projects
Project number Project name Employees assigned Employee number Employee name Job classification
7
Employee
PRO_NUM intended to be primary key, but it contains null values. Table entries invite data inconsistencies
Update
Modifying JOB_CLASS New employee must be assigned project (phantom project) If employee deleted, other vital data lost
Insertion
Deletion
10
Repeating group (any project can have a group of data entries) which should not to be appeared in relational table
11
Figure 4.3
12
Conversion to 1NF
13
Conversion to 1NF
Partial
based on part of composite primary key one nonprime attribute depends on another nonprime attribute
14
Transitive
Figure 4.4
15
DESIRED DEPENDENCIES
PROJ_NUM PROJ_NAME
PARTIAL DEPENDENCIES
TRANSITIVE DEPENDENCIES
16
1NF Summarized
All key attributes defined No repeating groups in table All attributes dependent on primary key
17
Conversion to 2NF
Start with 1NF format: Write each key component on separate line Write original key on last line Each component is new table Write dependent attributes after each key
PROJECT (PROJ_NUM, PROJ_NAME) EMPLOYEE (EMP_NUM, EMP_NAME, JOB_CLASS, CHG_HOUR) ASSIGN (PROJ_NUM, EMP_NUM, HOURS)
18
19
2NF Summarized
Conversion to 3NF
PROJECT (PROJ_NUM, PROJ_NAME) ASSIGN (PROJ_NUM, EMP_NUM, HOURS) EMPLOYEE (EMP_NUM, EMP_NAME, JOB_CLASS) JOB (JOB_CLASS, CHG_HOUR)
21
3NF Summarized
22
Additional DB Enhancements
Figure 4.6
23
24
25
Figure 4.7
26
Figure 4.8
27
28
Figure 4.9
29
Normalization should be part of the design process Make sure the proposed entities meet the required normal form before the table structures are created Used to redesign or modify the existing table structures. E-R Diagram provides macro view
30
Difficult to separate normalization from E-R diagramming Business rules must be determined
31
32
Figure 4.10
There is a transitive dependency
Already 3NF
33
Removal
PROJECT (PROJ_NUM, PROJ_NAME) EMPLOYEE(EMP_NUM, EMP_LNAME,EMP_FNAME,EMP_INITAL, JOB_CODE) JOB (JOB_CODE, JOB_DESCRIPTION, JOB_CHG_HOUR);
34
Figure 4.11
35
PROJECT (PROJ_NUM, PROJ_NAME, EMP_NUM) EMPLOYEE(EMP_NUM, EMP_LNAME,EMP_FNAME,EMP_INITAL, EMP_HIREDATE, JOB_CODE) JOB (JOB_CODE,, JOB_DESCRIPTION, JOB_CHG_HOUR); ASSIGN((ASSIGN_NUM, ASSIGN_DATE, ASSIGN_HOURS, ASSIGN_CHG_HOURS, ASSIGN_CHARGE, EMP_NUM, PROJ_JUM)
37
38
39
Conversion to 4NF
Denormalization
41
Denormalization
42
Data updates less efficient Indexing more cumbersome No simple strategies for creating views
43