06 - DB Design - 01
06 - DB Design - 01
Database Design
Normal forms & functional
dependencies
Sumber: http://web.stanford.edu/class/cs145/
University of Stanford
Database Design (1)
Functional dependencies
Student Courses
Student Courses
Mary CS145
Mary {CS145,CS229}
Mary CS229
Joe {CS145,CS106}
Joe CS145
Joe CS106
9
Constraints Prevent (some)
Anomalies in the Data
A poorly designed database causes anomalies:
Detecting Reduncancy
S N L R W H
123-22-3666 Attishoo 48 8 10 40
Hourly_Emps
231-31-5368 Smiley 22 8 10 30
131-24-3650 Smethurst 35 5 7 30
434-26-3751 Guldu 35 5 7 32
612-67-4134 Madayan 35 8 10 40
Hourly_Emps2
Functional Dependencies (FDs):
Refining an ER Diagram
Before:
1st diagram becomes: since
Workers(S,N,L,D,Si) name dname
Departments(D,M,B) ssn lot did budget
Lots associated with workers.
Suppose all workers in a Employees Works_In Departments
dept are assigned the same lot:
DL
Redundancy; fixed by:
Workers2(S,N,D,Si) Dept_Lots(D,L)
After:
budget
Departments(D,M,B) since
name dname
Can fine-tune this:
ssn did
Workers2(S,N,D,Si) lot
Departments(D,M,B,L)
Employees Works_In Departments
Functional Dependencies (FDs): Reasoning About FDs
Given some FDs, we can usually infer additional FDs:
title studio, star implies title studio and title star
title studio and title star implies title studio, star
title studio, studio star implies title star
But,
title, star studio does NOT necessarily imply that title
studio or that star studio
An FD f is implied by a set of FDs F if f holds whenever all
FDs in F hold.
Finding Functional Dependencies
Equivalent to asking: Given a set of FDs, F = {f1,fn}, does an FD g hold?
A1, , Am B1,,Bn
1. Split/Combine
A1 Am B1 Bn
A1, , Am B1,,Bn
is equivalent to
A1, , Am B1,,Bn
Reduction/Trivial
A1 Am
F=
{name} {color}
{category} {dept}
F=
{name} {color}
{category} {dept}
F= {name, category}+ =
{name} {color} {name, category, color, dept}
{category} {dept}
F= {name, category}+ =
{name} {color} {name, category, color, dept}
{category} {dept}
{name, category}+ =
{name, category, color, dept, price}
{color, category} {price}
37
Example
R(A,B,C,D,E,F) {A,B} {C}
{A,D} {E}
{B} {D}
{A,F} {B}