60 likes | 179 Views
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
E N D
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 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,classes WHERE t_sid=sid AND t_cid=cid AND c_name=‘6.830’
Hobby Schema Table key is Hobby, SSN “Wide” schema – has redundancy and anomalies in the presence of updates, inserts, and deletes Entity Relationship Diagram SSN Name n:n Person Hobby Address Cost Name
BCNFify Example for Hobbies Iter 1 S = SSN, H = Hobby, N = Name, A = Addr, C = Cost Iter 2 violates bcnf violates bcnf 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?