Presentation is loading. Please wait.

Presentation is loading. Please wait.

EECS 339 Lecture 3 Normalization Database Internals.

Similar presentations


Presentation on theme: "EECS 339 Lecture 3 Normalization Database Internals."— Presentation transcript:

1 EECS 339 Lecture 3 Normalization Database Internals

2 Hobby Schema SSNNameAddressHobbyCost 123johnmain stdolls$ 123johnmain stbugs$ 345marylake sttennis$$ 456joefirst stdolls$ “Wide” schema – has redundancy and anomalies in the presence of updates, inserts, and deletes Table key is Hobby, SSN Person Hobby SSN Address Name Cost n:n Entity Relationship Diagram

3 BCNFify Example for Hobbies SchemaFDs (S,H,N,A,C)S,H  N,A,C S  N, A H  C S = SSN, H = Hobby, N = Name, A = Addr, C = Cost violates bcnf SchemaFDs (S, N,A)S  N, A SchemaFDs (S,H, C)S,H  C H  C violates bcnf SchemaFDs (H, C)H  C SchemaFDs (S,H) Iter 1 Iter 2 key Iter 3

4 Non-BCNF Example AccountClientOffice AJoe1 BMary1 AJohn1 CJoe2 Primary Key is Client, Office Each Account is handled by exactly 1 Office Within a given Office, a given Client has exactly 1 Account  Violates BCNF! (account not a superkey) FDs: Client, Office  Account Account  Office Splitting into 1. Account,Office and 2. Client Loses correspondence between clients, offices, and accounts Redundancy!

5 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 AccountClientOffice AJoe1 BMary1 AJohn1 CJoe2 FDs: Client, Office  Account Account  Office

6 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?

7 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

8 Database Internals Outline Front End Admission Control Connection Management (sql) Parser (parse tree) Rewriter (parse tree) Planner & Optimizer (query plan) Executor Query System Storage System Access Methods Lock Manager Buffer Manager Log Manager


Download ppt "EECS 339 Lecture 3 Normalization Database Internals."

Similar presentations


Ads by Google