Normalizing Your Database CPT 242
Normalization 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 Slide 2
1st Normal Form Repeating attributes are removed from tables Stated another way - Eliminate repeating groups of fields CPT Slide 3
1st Normal Form- Problems Identified CPT 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
1st Normal Form-Completed CPT Slide 5 EMPLOYEES *paynum lname fname dept deptname empdate GLASSPURCH *paynum *purchdate doctor doctorphone 1 M
2nd 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 Slide 6
2nd Normal Form- Problems Identified CPT 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-Completed CPT Slide 8 GLASSPURCH *paynum *purchdate doctor (FK) EYEDOCTOR *doctor doctorphone 1 M
3rd 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 Slide 9
3rd Normal Form- Problems Identified CPT 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 PK DEPENDENT ON DEPT FIELD
3rd Normal Form-Completed CPT Slide 11 DEPARTMENT *dept deptname 1 M EMPLOYEES *paynum lname fname dept empdate
3NF - Entire DB CPT Slide 12 GLSSPUR *paynum *purchdate doctor(FK) EYEDR *doctor doctorph M 1 DEPT *dept deptname 1 M EMP *paynum lname fname dept empdate 1 M