The Relational Model
240 likes | 262 Vues
Learn how to normalize a relation using the relational model and candidate keys. Identify functional dependencies and determine if the relation has normalization problems. Split functional dependencies into separate relations and create referential integrity constraints.
The Relational Model
E N D
Presentation Transcript
The Relational Model Chapter Two Normalization
Normalization Process • Identify all candidate keys of the relation. • Identify all functional dependencies in the relation. • Exampine the determinants of the functional dependencies. If any determinant is NOT a candidate key, the relation has normalization problems. In this case…
Normalization Process 3a. Place the columns of the functional dependency in a new relation of their own. 3b. Make the determinant the functional dependency of the primary key of the new relation. 3c. Leave a copy of the determinant as a foreign key in the original relation. 3d. Create a referential integrity constraint between the original relation and the new relation.
Normalization Process 4. Repeat step 3 as many times as necessary until every determinant of every relation is a candidate key.
Normalization Process Consider: PRESCRIPTION (PrescriptionNumber, Date, Drug, Dosage, Customer Name, CustomerPhone, CustomerEmail)
Normalization Process Step 1: Identify all candidate keys of the relation. PrescriptionNumber – determines all other elements Date? Dosage? Drug? – nope. i.e. many prescriptions can be written on any particular date Customer info? – nope. A customer may have more than one prescription. Candidate Keys: PrescriptionNumber
Normalization Process Step 2: Identify all function dependencies in the relation. PrescriptionNumber determines all other attributes Drug Dosage? Nope – a drug can have more than one dosage. Same for Dosage Drug CustomerEmail (CustomerName, CustomerPhone) Functional dependencies: PrescriptionNumber, CustomerEmail
Normalization Process Step 3: Examine determinants. If any is not a candidate key, the relation has normalization problems. Split the functional dependency into relation of its own, make the determinant of the functional dependency the primary key: CUSTOMER (CustomerName, CustomerPhone, CustomerEmail)
Normalization Process Still Step 3: Leave a copy of CustomerEmail in original relation as a foreign key: PRESCRIPTION (PrescriptionNumber, Date, Drug, Dosage, CustomerEmail)
Normalization Process More Step 3: Create referential integrity constraint: CustomerEmail in PRESCRIPTION must exist in CustomerEmail in CUSTOMER Repeating step 3 determines that these two relations are now normalized!
Normalization Example 1 Table STU-DORM
Normalization Example 1 STU-DORM (StudentNum, StudentName, DormName) DORM (DormName, DormCost) Constraint: DormName in STU-DORM must exist in DormName in DORM
Normalization Example 2 Table EMPLOYEE
Normalization Example 2 EMPLOYEE (EmployeeNum, LastName, Email, Department) DEPARTMENT (Department, DeptPhone) Constraint: Department in Employee must exist in Department in DEPARTMENT
Normalization Example 3 Table MEETING
Normalization Example 3 MEETING (Attorney, ClientNumber, MeetingDate, Duration) CLIENT (ClientNumber, ClientName) Constraint: ClientNumber in MEETING must exist in ClientNumber in CLIENT
Normalization Example 4 Consider the following relation: GRADE (ClassName, Section, Term, Grade, StudentNumber, StudentName, Professor, Department, DepartmentEmail) Candidate keys? (Classname, Section, Term, StudentNumber) So… (Classname, Section, Term, StudentNumber) (Grade, StudentName, Professor, Department, ProfessorEmail)
Normalization Example 4 Other functional dependencies: StudentNumber StudentName Professor (Department, ProfessorEmail) (Classname, Section, Term) Professor Break these into own tables, leaving behind foreign keys…
Normalization Example 4 STUDENT (StudentNumber, StudentName) PROFESSOR (Professor, Department, ProfessorEmail) CLASS_PROFESSOR( ClassName, Section, Term, Professor) GRADE (ClassName, Section, Term, Grade, StudentNumber) With proper constraints on each.
The Null Value • A Null value means that no data was entered • This is different from a zero, space character, or tab character
The Problem of Null Values • A Null is often ambiguous. It could mean… • The column value is not appropriate for the specific row • The column value is not decided • The column value is unknown • Each may have entirely different implications