EECS 339 Lecture 3 Normalization Database Internals.
-
Upload
antonia-short -
Category
Documents
-
view
214 -
download
0
Transcript of EECS 339 Lecture 3 Normalization Database Internals.
EECS 339 Lecture 3
NormalizationDatabase Internals
Hobby SchemaSSN Name Address Hobby Cost
123 john main st dolls $
123 john main st bugs $
345 mary lake st tennis $$
456 joe first st dolls $
“Wide” schema – has redundancy and anomalies in the presence of updates, inserts, and deletes
Table key is Hobby, SSN
PersonPerson HobbyHobby
SSN
Address
Name
Name
Cost
n:n
Entity Relationship Diagram
BCNFify Example for Hobbies
Schema FDs
(S,H,N,A,C) S,H N,A,CS N, AH C
S = SSN, H = Hobby, N = Name, A = Addr, C = Cost
violates bcnf
Schema FDs
(S, N,A) S N, A
Schema FDs
(S,H, C) S,H CH C
violates bcnf
Schema FDs
(H, C) H C
Schema FDs
(S,H)
Iter 1
Iter 2
key
Iter 3
Non-BCNF ExampleAccount Client Office
A Joe 1
B Mary 1
A John 1
C Joe 2
Primary Key is Client, OfficeEach Account is handled by exactly 1 OfficeWithin a given Office, a given Client has exactly 1 Account
Violates BCNF! (account not a superkey)
FDs:Client, Office AccountAccount Office
Splitting into 1. Account,Office and2. Client
Loses correspondence between clients, offices, and accounts
Redundancy!
Third Normal Form vs. BCNF
• This is a minimal example of a table in “third normal form” (3NF) but not BCNF
• All tables in BCNF are also in 3NF• But 3NF allows redundancy to “preserve FDs”
– Meaning that all FDs can be checked in a single table
Account Client Office
A Joe 1
B Mary 1
A John 1
C Joe 2
FDs:Client, Office AccountAccount Office
Study Break• Patient database• Want to represent patients at hospitals with doctors• Patients have names, birthdates• Doctors have names, specialties• Hospitals have names, addresses• One doctor can treat multiple patients, each patient has one doctor• Each patient in one hospital, hospitals have many patients• Doctors work for one hospital, hospitals have many doctors
1) Draw an ER diagram
2) What are the functional dependencies?
3) What is the normalized schema? Is it in BCNF?
Study Break (cont’d)
• Write a SQL statement for:– Getting the names of all patients seeing Dr. X– Determining the average # of patients per hospital– Tallying up the # of doctors practicing each
specialty at each hospital
Database Internals OutlineFront End
Admission ControlConnection Management
(sql)Parser
(parse tree)Rewriter
(parse tree) Planner & Optimizer
(query plan) Executor
Query System
Storage System
Access MethodsLock ManagerBuffer ManagerLog Manager