Normalizing Your Database CPT 242. Normalization The procedure where the developer analyzes the data...

12
Normalizing Your Normalizing Your Database Database CPT 242 CPT 242

Transcript of Normalizing Your Database CPT 242. Normalization The procedure where the developer analyzes the data...

Normalizing Your Normalizing Your DatabaseDatabase

CPT 242CPT 242

NormalizationNormalization

The procedure where the developer analyzes the data and establishes the table structure to create the most efficient DB

Redundant data is eliminated, files will be as small as possible, and records will be easy to identify

1st, 2nd, 3rd Normal Form are the steps to normalize the data

CPT 242 - Slide 2

1st Normal Form1st Normal Form

Repeating attributes are removed from tables

Stated another way - Eliminate repeating groups of fields

CPT 242 - Slide 3

1st Normal Form-1st Normal Form-Problems IdentifiedProblems Identified

CPT 242 - Slide 4

EMPLOYEES*paynum lname fname dept deptname empdate glasspurch1 doctor1 doctor1phone glasspurch2 doctor2 doctor2phone

Remove from this table and create a new table to contain.

• Repeating attributes are removed from tables

REPEATING FIELD

REPEATING FIELD

REPEATING FIELD

REPEATING FIELD

REPEATING FIELD

REPEATING FIELD

1st Normal Form-Completed1st Normal Form-Completed

CPT 242 - Slide 5

EMPLOYEES*paynum lname fname dept deptname empdate

GLASSPURCH*paynum*purchdate doctor doctorphone

1M

2nd Normal Form2nd Normal Form

2NF violations can only occur in tables with composite PKs

All non-key fields in the table must be dependent on the entire PK

The fields must be dependent on the whole PK, not just part of a composite key

If fields are found that are not, they should be placed in their own table

CPT 242 - Slide 6

2nd Normal Form-2nd Normal Form-Problems IdentifiedProblems Identified

CPT 242 - Slide 7

GLASSPURCH*paynum*purchdate doctor doctorphone

• 2NF violations can only occur in tables with composite PKs

• All non-key fields in the table must be dependent on the entire PK

Remove from this table and create a new table to contain.NOT DEPENDENT

ON ENTIRE PK

2nd Normal Form-Completed2nd Normal Form-Completed

CPT 242 - Slide 8

GLASSPURCH*paynum*purchdate doctor (FK)

EYEDOCTOR*doctor doctorphone

1

M

3rd Normal Form3rd Normal Form

3NF violations can only occur in tables with single field PKs

All non-key columns are dependent on the PK and nothing but the PK

All non-key columns must be independent of each other

CPT 242 - Slide 9

3rd Normal Form-3rd Normal Form-Problems IdentifiedProblems Identified

CPT 242 - Slide 10

• 3NF violations can only occur in tables with single field PKs

• All non-key fields in the table must be dependent on the PK

• All non-key columns must be independent of each other

Remove from this table and create a new table to contain.

EMPLOYEES*paynum lname fname dept deptname empdate

NOT DEPENDENT ON PKDEPENDENT ON DEPT FIELD

3rd Normal Form-Completed3rd Normal Form-Completed

CPT 242 - Slide 11

DEPARTMENT*dept deptname

1

M

EMPLOYEES*paynum lname fname dept empdate

3NF - Entire DB3NF - Entire DB

CPT 242 - Slide 12

GLSSPUR*paynum*purchdate doctor(FK)

EYEDR*doctor doctorph

M

1DEPT*dept deptname

1

M

EMP*paynum lname fname dept empdate

1M