6.830 lecture 3
DESCRIPTION
6.830 Lecture 3. Relational Algebra and Normalization Feb 13. Study Break # 1. Schema: classes: ( cid , c_name, c_rid , …) rooms: ( rid , bldg, …) students: ( sid , s_name, …) takes: ( t_sid , t_cid ). SELECT s_name FROM student,takes,classes WHERE t_sid=sid AND t_cid=cid - PowerPoint PPT PresentationTRANSCRIPT
6.830 Lecture 3
Relational Algebra and NormalizationFeb 13
Study Break # 1Schema:
classes: (cid, c_name, c_rid, …)rooms: (rid, bldg, …)students: (sid, s_name, …)takes: (t_sid, t_cid)
SELECT s_name FROM student,takes,classesWHERE t_sid=sid AND t_cid=cid AND c_name=‘6.830’
Questions
• Write an equivalent relational algebra expression for this query
• Are there other possible expressions?• Do you think one would be more “efficient” to
execute? Why?
SELECT s_name FROM student,takes,classesWHERE t_sid=sid AND t_cid=cid AND c_name=‘6.830’
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
Study Break # 2• 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
1) Draw an ER diagram
2) What are the functional dependencies
3) What is the normalized schema? Is it redundancy free?