12
Chapter 2. The Relational Model (cont.) IST210 1

Chapter 2. The Relational Model (cont.) IST2101. Review: Functional Dependency A relationship between attributes: some attribute(s) determine the value

Embed Size (px)

Citation preview

Page 1: Chapter 2. The Relational Model (cont.) IST2101. Review: Functional Dependency A relationship between attributes: some attribute(s) determine the value

IST210 1

Chapter 2. The Relational Model (cont.)

Page 2: Chapter 2. The Relational Model (cont.) IST2101. Review: Functional Dependency A relationship between attributes: some attribute(s) determine the value

IST210 2

Review: Functional Dependency

• A relationship between attributes: some attribute(s) determine the value of some other attribute(s) in the same table– These attributes we name them determinant– The other attributes are functionally dependent on this

determinant

CookieCost = NumberOfBoxes * $5NumberOfBoxes CookieCost

CookieCost = NumberOfBoxes * UnitPrice(UnitPrice, NumberOfBoxes) CookieCost

determinant

The composite forms determinant

Functionally dependent on NumberofBoxes

Page 3: Chapter 2. The Relational Model (cont.) IST2101. Review: Functional Dependency A relationship between attributes: some attribute(s) determine the value

IST210 3

Determinant = Candidate Key?

DeterminantsCandidate Key

(StudentID, CourseID)StudentIDCourseID(StudentID, CourseID)

In a relation, a candidate key must be a determinant

In a relation, a determinant may not be a candidate key

A relation is well-formed if and only if every determinant is a candidate key.

Page 4: Chapter 2. The Relational Model (cont.) IST2101. Review: Functional Dependency A relationship between attributes: some attribute(s) determine the value

IST210 4

Normalization

• Normalization is a process of breaking a table with more than one theme into a set of tables to ensure that each table is well-formed– No data redundancy– Data can be inserted, deleted, or modified without

creating modification problems

Page 5: Chapter 2. The Relational Model (cont.) IST2101. Review: Functional Dependency A relationship between attributes: some attribute(s) determine the value

IST210 5

Normalization Principles

• Relational design principles for normalized relations:– To be a well-formed relation, every determinant

must be a candidate key– Any relation that is not well-formed should be

broken into two or more well-formed relations

Page 6: Chapter 2. The Relational Model (cont.) IST2101. Review: Functional Dependency A relationship between attributes: some attribute(s) determine the value

IST210 6

Normalization Process1. Identify all the candidate keys of the relation.2. Identify all the functional dependencies in the relation.3. Examine the determinants of the functional dependencies. If any

determinant is not a candidate key, the relation is not well formed. In this case:

a. Place the columns of the functional dependency in a new relation of their own.

b. Make the determinant of the functional dependency the primary key of the new relation.

c. Leave a copy of the determinant as a foreign key in the original relation.d. Create a referential integrity constraint between the original relation and

the new relation.

4. Repeat step 3 as many times as necessary until every determinant of every relation is a candidate key.

Page 7: Chapter 2. The Relational Model (cont.) IST2101. Review: Functional Dependency A relationship between attributes: some attribute(s) determine the value

IST210 7

Normalization Process: Exercise 1

Step 1. Candidate keys:

Step 2. Functional dependencies:

Step 3. Determine if the relation is well-formed. If not, split the relation into multiple well-formed relations and specify all the primary keys, foreign keys and referential integrity constraints:

Hint: If any determinant is not a candidate key, the relation is not well formed.

Page 8: Chapter 2. The Relational Model (cont.) IST2101. Review: Functional Dependency A relationship between attributes: some attribute(s) determine the value

IST210 8

Normalization Process: Exercise 2

Step 1. Candidate keys:

Step 2. Functional dependencies:

Step 3. Determine if the relation is well-formed. If not, split the relation into multiple well-formed relations and specify all the primary keys, foreign keys and referential integrity constraints:

Hint: If any determinant is not a candidate key, the relation is not well formed.

Page 9: Chapter 2. The Relational Model (cont.) IST2101. Review: Functional Dependency A relationship between attributes: some attribute(s) determine the value

IST210 9

Normalization Process: Exercise 3

Step 1. Candidate keys

Step 2. Functional dependencies

GRADE(ClassName, Section, Term, Grade, StudentNumber, StudentName, Professor, ProfessorDepartment, ProfessorEmail)

Step 3. Determine if the relation is well-formed. If not, split the relation into multiple well-formed relations and specify all the primary keys, foreign keys and referential integrity constraints:

Hint: If any determinant is not a candidate key, the relation is not well formed.

Page 10: Chapter 2. The Relational Model (cont.) IST2101. Review: Functional Dependency A relationship between attributes: some attribute(s) determine the value

True/False Quiz

• Given the functional dependency for the attributes of ENTITY1, X → (A, B, C), X is a candidate key for the relation ENTITY1 (A, B, C, X).

• Normalization is the process of removing all functional dependencies from a relation.

• In the normalization process, it is not necessary to identify all the functional dependencies in a relation.

• In the normalization process, if you find a candidate key that is not a primary key, then you have determined that the relation needs to be broken into two or more relations.

Page 11: Chapter 2. The Relational Model (cont.) IST2101. Review: Functional Dependency A relationship between attributes: some attribute(s) determine the value

IST210 11

Summary of Chapter 2

• Learn the concept of the relational model: entities, relations, relationships

• Learn the meaning and importance of keys, foreign keys, and related terminology

• Learn the meaning of functional dependencies• Learn to apply a process for normalizing

relations

Page 12: Chapter 2. The Relational Model (cont.) IST2101. Review: Functional Dependency A relationship between attributes: some attribute(s) determine the value

IST210 12

Assignment 2: Relational Model

• Due: 11:59pm on Sunday, 2/1