+ All Categories
Home > Documents > Third Normal Form - Undergraduate...

Third Normal Form - Undergraduate...

Date post: 07-Sep-2018
Category:
Upload: phungtuyen
View: 216 times
Download: 0 times
Share this document with a friend
36
Third Normal Form T. M. Murali November 3, 2010 T. M. Murali November 3, 2010 CS 4604: Third Normal Form
Transcript
Page 1: Third Normal Form - Undergraduate Coursescourses.cs.vt.edu/~cs4604/Fall10/lectures/lecture-17-3nf.pdf · Third Normal Form T. M. Murali November 3, 2010 T. M. Murali November 3, 2010

Third Normal Form

T. M. Murali

November 3, 2010

T. M. Murali November 3, 2010 CS 4604: Third Normal Form

Page 2: Third Normal Form - Undergraduate Coursescourses.cs.vt.edu/~cs4604/Fall10/lectures/lecture-17-3nf.pdf · Third Normal Form T. M. Murali November 3, 2010 T. M. Murali November 3, 2010

Preserving FDs in a Decomposition

I Consider the relation Teach(CourseNumber, DepartmentName,

Professor, Semester, Year)

I The relation models which courses a professor teaches in whichsemester.

I Do not assume that each course is taught by at most one professor.

I University introduces two new rules:1. Each professor teaches ≤ 1 course per semester.

PSY→ CD

2. Each course is taught either in the fall every year or in the spring everyyear.

CD→ S

I What are the keys?

{P,S ,Y } and {C ,D,P,Y }

I Decomposing using CD→ S yields

Teach1(C, D, S) and Teach2(C, D, P, Y).

Are both in BCNF?

I How do you enforce PSY→ CD?

Only by joining Teach1 and Teach2,which is expensive.

I The BCNF decomposition algorithm does not preserve FDs.

T. M. Murali November 3, 2010 CS 4604: Third Normal Form

Page 3: Third Normal Form - Undergraduate Coursescourses.cs.vt.edu/~cs4604/Fall10/lectures/lecture-17-3nf.pdf · Third Normal Form T. M. Murali November 3, 2010 T. M. Murali November 3, 2010

Preserving FDs in a Decomposition

I Consider the relation Teach(CourseNumber, DepartmentName,

Professor, Semester, Year)

I The relation models which courses a professor teaches in whichsemester.

I Do not assume that each course is taught by at most one professor.I University introduces two new rules:

1. Each professor teaches ≤ 1 course per semester.

PSY→ CD

2. Each course is taught either in the fall every year or in the spring everyyear.

CD→ S

I What are the keys?

{P,S ,Y } and {C ,D,P,Y }

I Decomposing using CD→ S yields

Teach1(C, D, S) and Teach2(C, D, P, Y).

Are both in BCNF?

I How do you enforce PSY→ CD?

Only by joining Teach1 and Teach2,which is expensive.

I The BCNF decomposition algorithm does not preserve FDs.

T. M. Murali November 3, 2010 CS 4604: Third Normal Form

Page 4: Third Normal Form - Undergraduate Coursescourses.cs.vt.edu/~cs4604/Fall10/lectures/lecture-17-3nf.pdf · Third Normal Form T. M. Murali November 3, 2010 T. M. Murali November 3, 2010

Preserving FDs in a Decomposition

I Consider the relation Teach(CourseNumber, DepartmentName,

Professor, Semester, Year)

I The relation models which courses a professor teaches in whichsemester.

I Do not assume that each course is taught by at most one professor.I University introduces two new rules:

1. Each professor teaches ≤ 1 course per semester. PSY→ CD

2. Each course is taught either in the fall every year or in the spring everyyear.

CD→ S

I What are the keys?

{P,S ,Y } and {C ,D,P,Y }

I Decomposing using CD→ S yields

Teach1(C, D, S) and Teach2(C, D, P, Y).

Are both in BCNF?

I How do you enforce PSY→ CD?

Only by joining Teach1 and Teach2,which is expensive.

I The BCNF decomposition algorithm does not preserve FDs.

T. M. Murali November 3, 2010 CS 4604: Third Normal Form

Page 5: Third Normal Form - Undergraduate Coursescourses.cs.vt.edu/~cs4604/Fall10/lectures/lecture-17-3nf.pdf · Third Normal Form T. M. Murali November 3, 2010 T. M. Murali November 3, 2010

Preserving FDs in a Decomposition

I Consider the relation Teach(CourseNumber, DepartmentName,

Professor, Semester, Year)

I The relation models which courses a professor teaches in whichsemester.

I Do not assume that each course is taught by at most one professor.I University introduces two new rules:

1. Each professor teaches ≤ 1 course per semester. PSY→ CD

2. Each course is taught either in the fall every year or in the spring everyyear. CD→ S

I What are the keys?

{P,S ,Y } and {C ,D,P,Y }

I Decomposing using CD→ S yields

Teach1(C, D, S) and Teach2(C, D, P, Y).

Are both in BCNF?

I How do you enforce PSY→ CD?

Only by joining Teach1 and Teach2,which is expensive.

I The BCNF decomposition algorithm does not preserve FDs.

T. M. Murali November 3, 2010 CS 4604: Third Normal Form

Page 6: Third Normal Form - Undergraduate Coursescourses.cs.vt.edu/~cs4604/Fall10/lectures/lecture-17-3nf.pdf · Third Normal Form T. M. Murali November 3, 2010 T. M. Murali November 3, 2010

Preserving FDs in a Decomposition

I Consider the relation Teach(CourseNumber, DepartmentName,

Professor, Semester, Year)

I The relation models which courses a professor teaches in whichsemester.

I Do not assume that each course is taught by at most one professor.I University introduces two new rules:

1. Each professor teaches ≤ 1 course per semester. PSY→ CD

2. Each course is taught either in the fall every year or in the spring everyyear. CD→ S

I What are the keys?

{P,S ,Y } and {C ,D,P,Y }I Decomposing using CD→ S yields

Teach1(C, D, S) and Teach2(C, D, P, Y).

Are both in BCNF?

I How do you enforce PSY→ CD?

Only by joining Teach1 and Teach2,which is expensive.

I The BCNF decomposition algorithm does not preserve FDs.

T. M. Murali November 3, 2010 CS 4604: Third Normal Form

Page 7: Third Normal Form - Undergraduate Coursescourses.cs.vt.edu/~cs4604/Fall10/lectures/lecture-17-3nf.pdf · Third Normal Form T. M. Murali November 3, 2010 T. M. Murali November 3, 2010

Preserving FDs in a Decomposition

I Consider the relation Teach(CourseNumber, DepartmentName,

Professor, Semester, Year)

I The relation models which courses a professor teaches in whichsemester.

I Do not assume that each course is taught by at most one professor.I University introduces two new rules:

1. Each professor teaches ≤ 1 course per semester. PSY→ CD

2. Each course is taught either in the fall every year or in the spring everyyear. CD→ S

I What are the keys? {P, S ,Y } and {C ,D,P,Y }

I Decomposing using CD→ S yields

Teach1(C, D, S) and Teach2(C, D, P, Y).

Are both in BCNF?

I How do you enforce PSY→ CD?

Only by joining Teach1 and Teach2,which is expensive.

I The BCNF decomposition algorithm does not preserve FDs.

T. M. Murali November 3, 2010 CS 4604: Third Normal Form

Page 8: Third Normal Form - Undergraduate Coursescourses.cs.vt.edu/~cs4604/Fall10/lectures/lecture-17-3nf.pdf · Third Normal Form T. M. Murali November 3, 2010 T. M. Murali November 3, 2010

Preserving FDs in a Decomposition

I Consider the relation Teach(CourseNumber, DepartmentName,

Professor, Semester, Year)

I The relation models which courses a professor teaches in whichsemester.

I Do not assume that each course is taught by at most one professor.I University introduces two new rules:

1. Each professor teaches ≤ 1 course per semester. PSY→ CD

2. Each course is taught either in the fall every year or in the spring everyyear. CD→ S

I What are the keys? {P, S ,Y } and {C ,D,P,Y }I Decomposing using CD→ S yields

Teach1(C, D, S) and Teach2(C, D, P, Y).

Are both in BCNF?

I How do you enforce PSY→ CD?

Only by joining Teach1 and Teach2,which is expensive.

I The BCNF decomposition algorithm does not preserve FDs.

T. M. Murali November 3, 2010 CS 4604: Third Normal Form

Page 9: Third Normal Form - Undergraduate Coursescourses.cs.vt.edu/~cs4604/Fall10/lectures/lecture-17-3nf.pdf · Third Normal Form T. M. Murali November 3, 2010 T. M. Murali November 3, 2010

Preserving FDs in a Decomposition

I Consider the relation Teach(CourseNumber, DepartmentName,

Professor, Semester, Year)

I The relation models which courses a professor teaches in whichsemester.

I Do not assume that each course is taught by at most one professor.I University introduces two new rules:

1. Each professor teaches ≤ 1 course per semester. PSY→ CD

2. Each course is taught either in the fall every year or in the spring everyyear. CD→ S

I What are the keys? {P, S ,Y } and {C ,D,P,Y }I Decomposing using CD→ S yields

Teach1(C, D, S) and Teach2(C, D, P, Y).

Are both in BCNF?I How do you enforce PSY→ CD?

Only by joining Teach1 and Teach2,which is expensive.

I The BCNF decomposition algorithm does not preserve FDs.

T. M. Murali November 3, 2010 CS 4604: Third Normal Form

Page 10: Third Normal Form - Undergraduate Coursescourses.cs.vt.edu/~cs4604/Fall10/lectures/lecture-17-3nf.pdf · Third Normal Form T. M. Murali November 3, 2010 T. M. Murali November 3, 2010

Preserving FDs in a Decomposition

I Consider the relation Teach(CourseNumber, DepartmentName,

Professor, Semester, Year)

I The relation models which courses a professor teaches in whichsemester.

I Do not assume that each course is taught by at most one professor.I University introduces two new rules:

1. Each professor teaches ≤ 1 course per semester. PSY→ CD

2. Each course is taught either in the fall every year or in the spring everyyear. CD→ S

I What are the keys? {P, S ,Y } and {C ,D,P,Y }I Decomposing using CD→ S yields

Teach1(C, D, S) and Teach2(C, D, P, Y). Are both in BCNF?

I How do you enforce PSY→ CD?

Only by joining Teach1 and Teach2,which is expensive.

I The BCNF decomposition algorithm does not preserve FDs.

T. M. Murali November 3, 2010 CS 4604: Third Normal Form

Page 11: Third Normal Form - Undergraduate Coursescourses.cs.vt.edu/~cs4604/Fall10/lectures/lecture-17-3nf.pdf · Third Normal Form T. M. Murali November 3, 2010 T. M. Murali November 3, 2010

Preserving FDs in a Decomposition

I Consider the relation Teach(CourseNumber, DepartmentName,

Professor, Semester, Year)

I The relation models which courses a professor teaches in whichsemester.

I Do not assume that each course is taught by at most one professor.I University introduces two new rules:

1. Each professor teaches ≤ 1 course per semester. PSY→ CD

2. Each course is taught either in the fall every year or in the spring everyyear. CD→ S

I What are the keys? {P, S ,Y } and {C ,D,P,Y }I Decomposing using CD→ S yields

Teach1(C, D, S) and Teach2(C, D, P, Y). Are both in BCNF?I How do you enforce PSY→ CD?

Only by joining Teach1 and Teach2,which is expensive.

I The BCNF decomposition algorithm does not preserve FDs.

T. M. Murali November 3, 2010 CS 4604: Third Normal Form

Page 12: Third Normal Form - Undergraduate Coursescourses.cs.vt.edu/~cs4604/Fall10/lectures/lecture-17-3nf.pdf · Third Normal Form T. M. Murali November 3, 2010 T. M. Murali November 3, 2010

Preserving FDs in a Decomposition

I Consider the relation Teach(CourseNumber, DepartmentName,

Professor, Semester, Year)

I The relation models which courses a professor teaches in whichsemester.

I Do not assume that each course is taught by at most one professor.I University introduces two new rules:

1. Each professor teaches ≤ 1 course per semester. PSY→ CD

2. Each course is taught either in the fall every year or in the spring everyyear. CD→ S

I What are the keys? {P, S ,Y } and {C ,D,P,Y }I Decomposing using CD→ S yields

Teach1(C, D, S) and Teach2(C, D, P, Y). Are both in BCNF?I How do you enforce PSY→ CD? Only by joining Teach1 and Teach2,

which is expensive.

I The BCNF decomposition algorithm does not preserve FDs.

T. M. Murali November 3, 2010 CS 4604: Third Normal Form

Page 13: Third Normal Form - Undergraduate Coursescourses.cs.vt.edu/~cs4604/Fall10/lectures/lecture-17-3nf.pdf · Third Normal Form T. M. Murali November 3, 2010 T. M. Murali November 3, 2010

Preserving FDs in a Decomposition

I Consider the relation Teach(CourseNumber, DepartmentName,

Professor, Semester, Year)

I The relation models which courses a professor teaches in whichsemester.

I Do not assume that each course is taught by at most one professor.I University introduces two new rules:

1. Each professor teaches ≤ 1 course per semester. PSY→ CD

2. Each course is taught either in the fall every year or in the spring everyyear. CD→ S

I What are the keys? {P, S ,Y } and {C ,D,P,Y }I Decomposing using CD→ S yields

Teach1(C, D, S) and Teach2(C, D, P, Y). Are both in BCNF?I How do you enforce PSY→ CD? Only by joining Teach1 and Teach2,

which is expensive.I The BCNF decomposition algorithm does not preserve FDs.

T. M. Murali November 3, 2010 CS 4604: Third Normal Form

Page 14: Third Normal Form - Undergraduate Coursescourses.cs.vt.edu/~cs4604/Fall10/lectures/lecture-17-3nf.pdf · Third Normal Form T. M. Murali November 3, 2010 T. M. Murali November 3, 2010

Third Normal Form

I A relation R is in Third Normal Form (3NF) if and only if for everynon-trivial FD A1 A2 . . . An → B for R, one of the following twoconditions is true:

1. {A1,A2, . . . ,An} is a superkey for R or2. B is prime, i.e., B is an attribute in some key for R.

I Teach(C, D, P, S, Y) has FDs PSY→ CD and CD→ S

I Keys are {P,S ,Y } and {C ,D,P,Y }.I CD→ S violates BCNF.

I However, Teach is in 3NF because S is a part of a key.

T. M. Murali November 3, 2010 CS 4604: Third Normal Form

Page 15: Third Normal Form - Undergraduate Coursescourses.cs.vt.edu/~cs4604/Fall10/lectures/lecture-17-3nf.pdf · Third Normal Form T. M. Murali November 3, 2010 T. M. Murali November 3, 2010

Third Normal Form

I A relation R is in Third Normal Form (3NF) if and only if for everynon-trivial FD A1 A2 . . . An → B for R, one of the following twoconditions is true:

1. {A1,A2, . . . ,An} is a superkey for R or2. B is prime, i.e., B is an attribute in some key for R.

I Teach(C, D, P, S, Y) has FDs PSY→ CD and CD→ S

I Keys are {P, S ,Y } and {C ,D,P,Y }.I CD→ S violates BCNF.

I However, Teach is in 3NF because S is a part of a key.

T. M. Murali November 3, 2010 CS 4604: Third Normal Form

Page 16: Third Normal Form - Undergraduate Coursescourses.cs.vt.edu/~cs4604/Fall10/lectures/lecture-17-3nf.pdf · Third Normal Form T. M. Murali November 3, 2010 T. M. Murali November 3, 2010

More 3NF Examples

I Consider the relation Teach(CourseNumber, DepartmentName,

Professor, Semester, Year)

I The relation models which courses a professor teaches in whichsemester.

I Modify the second rule and repeat the analysis:

1. Each professor teaches ≤ 1 course per semester. PSY→ CD

2. In a year, each course is taught either in the fall or in the spring.

Thesemester a course is taught in can change from year to year. CDY→ S.Keys are {P,S ,Y } and {C ,D,P,Y }. Still in 3NF.

3. Add the following constraint and repeat the analysis: Every time it isoffered, each course is taught by at most one professor.

CDYS → P(new), PSY → CD (old), and CDY → S (old). Keys are {P,S ,Y }and {C ,D,Y }. Still in 3NF.

4. Modify the previous constraint: Over all offerings, each course istaught by at most one professor.

CD → P (new), PSY → CD (old),and CDY → S (old). Keys are {P,S ,Y } and {C ,D,Y }. Still in 3NF.

T. M. Murali November 3, 2010 CS 4604: Third Normal Form

Page 17: Third Normal Form - Undergraduate Coursescourses.cs.vt.edu/~cs4604/Fall10/lectures/lecture-17-3nf.pdf · Third Normal Form T. M. Murali November 3, 2010 T. M. Murali November 3, 2010

More 3NF Examples

I Consider the relation Teach(CourseNumber, DepartmentName,

Professor, Semester, Year)

I The relation models which courses a professor teaches in whichsemester.

I Modify the second rule and repeat the analysis:

1. Each professor teaches ≤ 1 course per semester. PSY→ CD

2. In a year, each course is taught either in the fall or in the spring.

Thesemester a course is taught in can change from year to year. CDY→ S.Keys are {P,S ,Y } and {C ,D,P,Y }. Still in 3NF.

3. Add the following constraint and repeat the analysis: Every time it isoffered, each course is taught by at most one professor.

CDYS → P(new), PSY → CD (old), and CDY → S (old). Keys are {P,S ,Y }and {C ,D,Y }. Still in 3NF.

4. Modify the previous constraint: Over all offerings, each course istaught by at most one professor.

CD → P (new), PSY → CD (old),and CDY → S (old). Keys are {P,S ,Y } and {C ,D,Y }. Still in 3NF.

T. M. Murali November 3, 2010 CS 4604: Third Normal Form

Page 18: Third Normal Form - Undergraduate Coursescourses.cs.vt.edu/~cs4604/Fall10/lectures/lecture-17-3nf.pdf · Third Normal Form T. M. Murali November 3, 2010 T. M. Murali November 3, 2010

More 3NF Examples

I Consider the relation Teach(CourseNumber, DepartmentName,

Professor, Semester, Year)

I The relation models which courses a professor teaches in whichsemester.

I Modify the second rule and repeat the analysis:

1. Each professor teaches ≤ 1 course per semester. PSY→ CD

2. In a year, each course is taught either in the fall or in the spring. Thesemester a course is taught in can change from year to year.

CDY→ S.Keys are {P,S ,Y } and {C ,D,P,Y }. Still in 3NF.

3. Add the following constraint and repeat the analysis: Every time it isoffered, each course is taught by at most one professor.

CDYS → P(new), PSY → CD (old), and CDY → S (old). Keys are {P,S ,Y }and {C ,D,Y }. Still in 3NF.

4. Modify the previous constraint: Over all offerings, each course istaught by at most one professor.

CD → P (new), PSY → CD (old),and CDY → S (old). Keys are {P,S ,Y } and {C ,D,Y }. Still in 3NF.

T. M. Murali November 3, 2010 CS 4604: Third Normal Form

Page 19: Third Normal Form - Undergraduate Coursescourses.cs.vt.edu/~cs4604/Fall10/lectures/lecture-17-3nf.pdf · Third Normal Form T. M. Murali November 3, 2010 T. M. Murali November 3, 2010

More 3NF Examples

I Consider the relation Teach(CourseNumber, DepartmentName,

Professor, Semester, Year)

I The relation models which courses a professor teaches in whichsemester.

I Modify the second rule and repeat the analysis:

1. Each professor teaches ≤ 1 course per semester. PSY→ CD

2. In a year, each course is taught either in the fall or in the spring. Thesemester a course is taught in can change from year to year. CDY→ S.Keys are {P,S ,Y } and {C ,D,P,Y }. Still in 3NF.

3. Add the following constraint and repeat the analysis: Every time it isoffered, each course is taught by at most one professor.

CDYS → P(new), PSY → CD (old), and CDY → S (old). Keys are {P,S ,Y }and {C ,D,Y }. Still in 3NF.

4. Modify the previous constraint: Over all offerings, each course istaught by at most one professor.

CD → P (new), PSY → CD (old),and CDY → S (old). Keys are {P,S ,Y } and {C ,D,Y }. Still in 3NF.

T. M. Murali November 3, 2010 CS 4604: Third Normal Form

Page 20: Third Normal Form - Undergraduate Coursescourses.cs.vt.edu/~cs4604/Fall10/lectures/lecture-17-3nf.pdf · Third Normal Form T. M. Murali November 3, 2010 T. M. Murali November 3, 2010

More 3NF Examples

I Consider the relation Teach(CourseNumber, DepartmentName,

Professor, Semester, Year)

I The relation models which courses a professor teaches in whichsemester.

I Modify the second rule and repeat the analysis:

1. Each professor teaches ≤ 1 course per semester. PSY→ CD

2. In a year, each course is taught either in the fall or in the spring. Thesemester a course is taught in can change from year to year. CDY→ S.Keys are {P,S ,Y } and {C ,D,P,Y }. Still in 3NF.

3. Add the following constraint and repeat the analysis: Every time it isoffered, each course is taught by at most one professor.

CDYS → P(new), PSY → CD (old), and CDY → S (old). Keys are {P,S ,Y }and {C ,D,Y }. Still in 3NF.

4. Modify the previous constraint: Over all offerings, each course istaught by at most one professor.

CD → P (new), PSY → CD (old),and CDY → S (old). Keys are {P,S ,Y } and {C ,D,Y }. Still in 3NF.

T. M. Murali November 3, 2010 CS 4604: Third Normal Form

Page 21: Third Normal Form - Undergraduate Coursescourses.cs.vt.edu/~cs4604/Fall10/lectures/lecture-17-3nf.pdf · Third Normal Form T. M. Murali November 3, 2010 T. M. Murali November 3, 2010

More 3NF Examples

I Consider the relation Teach(CourseNumber, DepartmentName,

Professor, Semester, Year)

I The relation models which courses a professor teaches in whichsemester.

I Modify the second rule and repeat the analysis:

1. Each professor teaches ≤ 1 course per semester. PSY→ CD

2. In a year, each course is taught either in the fall or in the spring. Thesemester a course is taught in can change from year to year. CDY→ S.Keys are {P,S ,Y } and {C ,D,P,Y }. Still in 3NF.

3. Add the following constraint and repeat the analysis: Every time it isoffered, each course is taught by at most one professor. CDYS → P(new), PSY → CD (old), and CDY → S (old). Keys are {P,S ,Y }and {C ,D,Y }. Still in 3NF.

4. Modify the previous constraint: Over all offerings, each course istaught by at most one professor.

CD → P (new), PSY → CD (old),and CDY → S (old). Keys are {P,S ,Y } and {C ,D,Y }. Still in 3NF.

T. M. Murali November 3, 2010 CS 4604: Third Normal Form

Page 22: Third Normal Form - Undergraduate Coursescourses.cs.vt.edu/~cs4604/Fall10/lectures/lecture-17-3nf.pdf · Third Normal Form T. M. Murali November 3, 2010 T. M. Murali November 3, 2010

More 3NF Examples

I Consider the relation Teach(CourseNumber, DepartmentName,

Professor, Semester, Year)

I The relation models which courses a professor teaches in whichsemester.

I Modify the second rule and repeat the analysis:

1. Each professor teaches ≤ 1 course per semester. PSY→ CD

2. In a year, each course is taught either in the fall or in the spring. Thesemester a course is taught in can change from year to year. CDY→ S.Keys are {P,S ,Y } and {C ,D,P,Y }. Still in 3NF.

3. Add the following constraint and repeat the analysis: Every time it isoffered, each course is taught by at most one professor. CDYS → P(new), PSY → CD (old), and CDY → S (old). Keys are {P,S ,Y }and {C ,D,Y }. Still in 3NF.

4. Modify the previous constraint: Over all offerings, each course istaught by at most one professor.

CD → P (new), PSY → CD (old),and CDY → S (old). Keys are {P,S ,Y } and {C ,D,Y }. Still in 3NF.

T. M. Murali November 3, 2010 CS 4604: Third Normal Form

Page 23: Third Normal Form - Undergraduate Coursescourses.cs.vt.edu/~cs4604/Fall10/lectures/lecture-17-3nf.pdf · Third Normal Form T. M. Murali November 3, 2010 T. M. Murali November 3, 2010

More 3NF Examples

I Consider the relation Teach(CourseNumber, DepartmentName,

Professor, Semester, Year)

I The relation models which courses a professor teaches in whichsemester.

I Modify the second rule and repeat the analysis:

1. Each professor teaches ≤ 1 course per semester. PSY→ CD

2. In a year, each course is taught either in the fall or in the spring. Thesemester a course is taught in can change from year to year. CDY→ S.Keys are {P,S ,Y } and {C ,D,P,Y }. Still in 3NF.

3. Add the following constraint and repeat the analysis: Every time it isoffered, each course is taught by at most one professor. CDYS → P(new), PSY → CD (old), and CDY → S (old). Keys are {P,S ,Y }and {C ,D,Y }. Still in 3NF.

4. Modify the previous constraint: Over all offerings, each course istaught by at most one professor. CD → P (new), PSY → CD (old),and CDY → S (old). Keys are {P,S ,Y } and {C ,D,Y }. Still in 3NF.

T. M. Murali November 3, 2010 CS 4604: Third Normal Form

Page 24: Third Normal Form - Undergraduate Coursescourses.cs.vt.edu/~cs4604/Fall10/lectures/lecture-17-3nf.pdf · Third Normal Form T. M. Murali November 3, 2010 T. M. Murali November 3, 2010

Decomposition into 3NF

I We can always decompose a relational schema R into a set S ofschemas that are dependency-preserving, i.e.,

I each relation in S is in 3NF,I the decomposition of R into S is lossless-join,I the decomposition into S is dependency-preserving, i.e., for each FD

that holds in R, there is a relation in S that allows that FD to bechecked.

I However, the relations may not be in BCNF and may contain someredundancy.

T. M. Murali November 3, 2010 CS 4604: Third Normal Form

Page 25: Third Normal Form - Undergraduate Coursescourses.cs.vt.edu/~cs4604/Fall10/lectures/lecture-17-3nf.pdf · Third Normal Form T. M. Murali November 3, 2010 T. M. Murali November 3, 2010

Decomposition into 3NF

I We can always decompose a relational schema R into a set S ofschemas that are dependency-preserving, i.e.,

I each relation in S is in 3NF,I the decomposition of R into S is lossless-join,I the decomposition into S is dependency-preserving, i.e., for each FD

that holds in R, there is a relation in S that allows that FD to bechecked.

I However, the relations may not be in BCNF and may contain someredundancy.

T. M. Murali November 3, 2010 CS 4604: Third Normal Form

Page 26: Third Normal Form - Undergraduate Coursescourses.cs.vt.edu/~cs4604/Fall10/lectures/lecture-17-3nf.pdf · Third Normal Form T. M. Murali November 3, 2010 T. M. Murali November 3, 2010

3NF Synthesis Algorithm

I Let F be the set of all FDs of R.

I We will compute a lossless-join, dependency-preserving decompositionof R into S, where every relation in S is in 3NF.

1. Find a minimal basis for F , say G.

2. For every FD X → A in G, use X ∪ A as the schema for one of therelations in S.

3. If the attributes in none of the relations in S form a superkey for R,add another relation to S whose schema is a key for R.

I Read Chapter 3.5.3 of the textbook to understand why this algorithmworks.

T. M. Murali November 3, 2010 CS 4604: Third Normal Form

Page 27: Third Normal Form - Undergraduate Coursescourses.cs.vt.edu/~cs4604/Fall10/lectures/lecture-17-3nf.pdf · Third Normal Form T. M. Murali November 3, 2010 T. M. Murali November 3, 2010

3NF Synthesis Algorithm

I Let F be the set of all FDs of R.

I We will compute a lossless-join, dependency-preserving decompositionof R into S, where every relation in S is in 3NF.

1. Find a minimal basis for F , say G.

2. For every FD X → A in G, use X ∪ A as the schema for one of therelations in S.

3. If the attributes in none of the relations in S form a superkey for R,add another relation to S whose schema is a key for R.

I Read Chapter 3.5.3 of the textbook to understand why this algorithmworks.

T. M. Murali November 3, 2010 CS 4604: Third Normal Form

Page 28: Third Normal Form - Undergraduate Coursescourses.cs.vt.edu/~cs4604/Fall10/lectures/lecture-17-3nf.pdf · Third Normal Form T. M. Murali November 3, 2010 T. M. Murali November 3, 2010

3NF Synthesis Algorithm

I Let F be the set of all FDs of R.

I We will compute a lossless-join, dependency-preserving decompositionof R into S, where every relation in S is in 3NF.

1. Find a minimal basis for F , say G.

2. For every FD X → A in G, use X ∪ A as the schema for one of therelations in S.

3. If the attributes in none of the relations in S form a superkey for R,add another relation to S whose schema is a key for R.

I Read Chapter 3.5.3 of the textbook to understand why this algorithmworks.

T. M. Murali November 3, 2010 CS 4604: Third Normal Form

Page 29: Third Normal Form - Undergraduate Coursescourses.cs.vt.edu/~cs4604/Fall10/lectures/lecture-17-3nf.pdf · Third Normal Form T. M. Murali November 3, 2010 T. M. Murali November 3, 2010

Computing a Minimal Basis

I See step 3 of Algorithm 3.12 on page 82 of your textbook.

I Start with a set F of FDs and compute a mimimal basis G.

1. If there is an FD D in F that follows from the other FDs in F ,remove D from F .

2. Let Y → B be an FD in F with at least two attributes in Y and letZ be Y with one of its attributes removed. If Z → B follows fromthe FDs in F , replace Y → B by Z → B.

3. Repeat the first two steps until no more changes can be made to F .

T. M. Murali November 3, 2010 CS 4604: Third Normal Form

Page 30: Third Normal Form - Undergraduate Coursescourses.cs.vt.edu/~cs4604/Fall10/lectures/lecture-17-3nf.pdf · Third Normal Form T. M. Murali November 3, 2010 T. M. Murali November 3, 2010

Computing a Minimal Basis

I See step 3 of Algorithm 3.12 on page 82 of your textbook.

I Start with a set F of FDs and compute a mimimal basis G.

1. If there is an FD D in F that follows from the other FDs in F ,remove D from F .

2. Let Y → B be an FD in F with at least two attributes in Y and letZ be Y with one of its attributes removed. If Z → B follows fromthe FDs in F , replace Y → B by Z → B.

3. Repeat the first two steps until no more changes can be made to F .

T. M. Murali November 3, 2010 CS 4604: Third Normal Form

Page 31: Third Normal Form - Undergraduate Coursescourses.cs.vt.edu/~cs4604/Fall10/lectures/lecture-17-3nf.pdf · Third Normal Form T. M. Murali November 3, 2010 T. M. Murali November 3, 2010

Example of 3NF Synthesis Algorithm

I (Handout 3, Problem 1, part 10) Apply the 3NF synthesis algorithmto the Inventory relation. Are all the relations in BCNF?

I (Handout 3, Problem 2, part 11) Apply the 3NF synthesis algorithmto the Concerts relation. Are all the resulting relations in BCNF?Resulting schema is exactly the one we get by applying the BCNFnormalisation algorithm to the FD City Year→ Venue Month Date.

I Apply BCNF normalisation algorithm to Concerts2. Are the resultingrelations in 3NF? Is the decomposition dependency-preserving?

I Suppose we apply the BCNF normalisation algorithm to Concerts

using the FD Song→ Album and perform no more decompositions.Resulting relations have schemas {Song, Album} and{Song, City, Venue, Year, Month, Date}. This decompositionis in 3NF but is not dependency-preserving.

T. M. Murali November 3, 2010 CS 4604: Third Normal Form

Page 32: Third Normal Form - Undergraduate Coursescourses.cs.vt.edu/~cs4604/Fall10/lectures/lecture-17-3nf.pdf · Third Normal Form T. M. Murali November 3, 2010 T. M. Murali November 3, 2010

Example of 3NF Synthesis Algorithm

I (Handout 3, Problem 1, part 10) Apply the 3NF synthesis algorithmto the Inventory relation. Are all the relations in BCNF?

I (Handout 3, Problem 2, part 11) Apply the 3NF synthesis algorithmto the Concerts relation. Are all the resulting relations in BCNF?

Resulting schema is exactly the one we get by applying the BCNFnormalisation algorithm to the FD City Year→ Venue Month Date.

I Apply BCNF normalisation algorithm to Concerts2. Are the resultingrelations in 3NF? Is the decomposition dependency-preserving?

I Suppose we apply the BCNF normalisation algorithm to Concerts

using the FD Song→ Album and perform no more decompositions.Resulting relations have schemas {Song, Album} and{Song, City, Venue, Year, Month, Date}. This decompositionis in 3NF but is not dependency-preserving.

T. M. Murali November 3, 2010 CS 4604: Third Normal Form

Page 33: Third Normal Form - Undergraduate Coursescourses.cs.vt.edu/~cs4604/Fall10/lectures/lecture-17-3nf.pdf · Third Normal Form T. M. Murali November 3, 2010 T. M. Murali November 3, 2010

Example of 3NF Synthesis Algorithm

I (Handout 3, Problem 1, part 10) Apply the 3NF synthesis algorithmto the Inventory relation. Are all the relations in BCNF?

I (Handout 3, Problem 2, part 11) Apply the 3NF synthesis algorithmto the Concerts relation. Are all the resulting relations in BCNF?Resulting schema is exactly the one we get by applying the BCNFnormalisation algorithm to the FD City Year→ Venue Month Date.

I Apply BCNF normalisation algorithm to Concerts2. Are the resultingrelations in 3NF? Is the decomposition dependency-preserving?

I Suppose we apply the BCNF normalisation algorithm to Concerts

using the FD Song→ Album and perform no more decompositions.Resulting relations have schemas {Song, Album} and{Song, City, Venue, Year, Month, Date}. This decompositionis in 3NF but is not dependency-preserving.

T. M. Murali November 3, 2010 CS 4604: Third Normal Form

Page 34: Third Normal Form - Undergraduate Coursescourses.cs.vt.edu/~cs4604/Fall10/lectures/lecture-17-3nf.pdf · Third Normal Form T. M. Murali November 3, 2010 T. M. Murali November 3, 2010

Example of 3NF Synthesis Algorithm

I (Handout 3, Problem 1, part 10) Apply the 3NF synthesis algorithmto the Inventory relation. Are all the relations in BCNF?

I (Handout 3, Problem 2, part 11) Apply the 3NF synthesis algorithmto the Concerts relation. Are all the resulting relations in BCNF?Resulting schema is exactly the one we get by applying the BCNFnormalisation algorithm to the FD City Year→ Venue Month Date.

I Apply BCNF normalisation algorithm to Concerts2. Are the resultingrelations in 3NF? Is the decomposition dependency-preserving?

I Suppose we apply the BCNF normalisation algorithm to Concerts

using the FD Song→ Album and perform no more decompositions.Resulting relations have schemas {Song, Album} and{Song, City, Venue, Year, Month, Date}. This decompositionis in 3NF but is not dependency-preserving.

T. M. Murali November 3, 2010 CS 4604: Third Normal Form

Page 35: Third Normal Form - Undergraduate Coursescourses.cs.vt.edu/~cs4604/Fall10/lectures/lecture-17-3nf.pdf · Third Normal Form T. M. Murali November 3, 2010 T. M. Murali November 3, 2010

Example of 3NF Synthesis Algorithm

I (Handout 3, Problem 1, part 10) Apply the 3NF synthesis algorithmto the Inventory relation. Are all the relations in BCNF?

I (Handout 3, Problem 2, part 11) Apply the 3NF synthesis algorithmto the Concerts relation. Are all the resulting relations in BCNF?Resulting schema is exactly the one we get by applying the BCNFnormalisation algorithm to the FD City Year→ Venue Month Date.

I Apply BCNF normalisation algorithm to Concerts2. Are the resultingrelations in 3NF? Is the decomposition dependency-preserving?

I Suppose we apply the BCNF normalisation algorithm to Concerts

using the FD Song→ Album and perform no more decompositions.

Resulting relations have schemas {Song, Album} and{Song, City, Venue, Year, Month, Date}. This decompositionis in 3NF but is not dependency-preserving.

T. M. Murali November 3, 2010 CS 4604: Third Normal Form

Page 36: Third Normal Form - Undergraduate Coursescourses.cs.vt.edu/~cs4604/Fall10/lectures/lecture-17-3nf.pdf · Third Normal Form T. M. Murali November 3, 2010 T. M. Murali November 3, 2010

Example of 3NF Synthesis Algorithm

I (Handout 3, Problem 1, part 10) Apply the 3NF synthesis algorithmto the Inventory relation. Are all the relations in BCNF?

I (Handout 3, Problem 2, part 11) Apply the 3NF synthesis algorithmto the Concerts relation. Are all the resulting relations in BCNF?Resulting schema is exactly the one we get by applying the BCNFnormalisation algorithm to the FD City Year→ Venue Month Date.

I Apply BCNF normalisation algorithm to Concerts2. Are the resultingrelations in 3NF? Is the decomposition dependency-preserving?

I Suppose we apply the BCNF normalisation algorithm to Concerts

using the FD Song→ Album and perform no more decompositions.Resulting relations have schemas {Song, Album} and{Song, City, Venue, Year, Month, Date}. This decompositionis in 3NF but is not dependency-preserving.

T. M. Murali November 3, 2010 CS 4604: Third Normal Form


Recommended