C20.0046- Database Management SystemsLecture #5.ppt
《C20.0046- Database Management SystemsLecture #5.ppt》由会员分享,可在线阅读,更多相关《C20.0046- Database Management SystemsLecture #5.ppt(39页珍藏版)》请在麦多课文档分享上搜索。
1、M.P. Johnson, DBMS, Stern/NYU, Spring 2008,1,C20.0046: Database Management Systems Lecture #5,M.P. Johnson Stern School of Business, NYU Spring, 2008,M.P. Johnson, DBMS, Stern/NYU, Spring 2008,2,Agenda,Last time: FDs This time: Anomalies Normalization: BCNF & 3NF Next time: SQL,M.P. Johnson, DBMS, S
2、tern/NYU, Spring 2008,3,Review: FDs,Definition:Notation: Read as: Ai functionally determines Bj,If two tuples agree on the attributes,A1, A2, , An,A1, A2, , An B1, B2, , Bm,M.P. Johnson, DBMS, Stern/NYU, Spring 2008,4,Review: Combining FDs,If some FDs are satisfied, then others are satisfied too,If
3、all these FDs are true:,name color category department color, category price,Then this FD also holds:,name, category price,Why?,M.P. Johnson, DBMS, Stern/NYU, Spring 2008,5,Problem: find all FDs,Given a relation instance and set of given FDs Find all FDs satisfied by that instanceUseful if we dont g
4、et enough information from our users: need to reverse engineer a data instanceQ: How long does this take? A: Some time for each subset of atts Q: How many subsets? powerset exponential time in worst-case But can often be smarter,M.P. Johnson, DBMS, Stern/NYU, Spring 2008,6,Closure Algorithm,Start wi
5、th X=A1, , An.Repeat:if B1, , Bn C is a FD andB1, , Bn are all in Xthen add C to X.until X didnt change,name, category+ = name, category, color, department, price,name color category department color, category price,Example:,M.P. Johnson, DBMS, Stern/NYU, Spring 2008,7,Closure alg e.g.,A, B C A, D B
6、 B D,Example:,Compute X+, for every set X (AB is shorthand for A,B):,A+ = A, B+ = BD, C+ = C, D+ = D AB+ = ABCD, AC+ = AC, AD+ = ABCD, BC+ = BC, BD+ = BD, CD+ = CD ABC+ = ABD+ = ACD+ = ABCD (no need to computewhy?) BCD+ = BCD, ABCD+ = ABCD,What are the keys?,M.P. Johnson, DBMS, Stern/NYU, Spring 200
7、8,8,Closure alg e.g.,Compute A,B+ X = A, B, Compute A, F+ X = A, F, ,R(A,B,C,D,E,F),A, B C A, D E B D A, F B,In class:,What are the keys?,M.P. Johnson, DBMS, Stern/NYU, Spring 2008,9,Closure alg e.g.,Product(name, price, category, color) name, category price category colorFDs are: Keys are: name, ca
8、tegoryEnrollment(student, address, course, room, time) student address room, time course student, course room, timeFDs are: Keys are:,M.P. Johnson, DBMS, Stern/NYU, Spring 2008,10,Next topic: Anomalies,Identify anomalies in existing schemataDecomposition by projectionBCNFLossy v. losslessThird Norma
9、l Form,M.P. Johnson, DBMS, Stern/NYU, Spring 2008,11,Types of anomalies,Redundancy Repeat info unnecessarily in several tuplesUpdate anomalies: Change info in one tuple but not in anotherDeletion anomalies: Delete some values & lose other values tooInsert anomalies: Inserting row means having to ins
10、ert other, separate info / null-ing it out,M.P. Johnson, DBMS, Stern/NYU, Spring 2008,12,Examples of anomalies,Redundancy: name, maddress Update anomaly: Bill moves Delete anom.: Bill doesnt pay bills, lose phones lose Bill! Insert anom: cant insert someone without a (non-null) phone Underlying caus
11、e: SSN-phone is many-many Effect: partial dependency ssn name, maddress, Whereas key = ssn,phone,SSN Name, Mailing-address,SSN Phone,M.P. Johnson, DBMS, Stern/NYU, Spring 2008,13,Decomposition by projection,Soln: replace anomalous R with projections of R onto two subsets of attributes Projection: an
12、 operation in Relational Algebra Corresponds to SELECT command in SQLProjecting R onto attributes (A1,An) means removing all other attributes Result of projection is another relation Yields tuples whose fields are A1,An Resulting duplicates ignored,M.P. Johnson, DBMS, Stern/NYU, Spring 2008,14,Proje
13、ction for decomposition,R1 = projection of R on A1, ., An, B1, ., Bm R2 = projection of R on A1, ., An, C1, ., Cp A1, ., An B1, ., Bm C1, ., Cp = all attributes R1 and R2 may (/not) be reassembled to produce original R,R(A1, ., An, B1, ., Bm, C1, ., Cp),M.P. Johnson, DBMS, Stern/NYU, Spring 2008,15,
14、Decomposition example,The anomalies are gone No more redundant data Easy to for Bill to move Okay for Bill to lose all phones,Break the relation into two:,M.P. Johnson, DBMS, Stern/NYU, Spring 2008,16,Thus: high-level strategy,E/R Model:,M.P. Johnson, DBMS, Stern/NYU, Spring 2008,17,Using FDs to pro
15、duce good schemas,Start with set of relations Define FDs (and keys) for them based on real world Transform your relations to “normal form” (normalize them) Do this using “decomposition”Intuitively, good design means No anomalies Can reconstruct all (and only the) original information,M.P. Johnson, D
16、BMS, Stern/NYU, Spring 2008,18,Decomposition terminology,Projection: eliminating certain atts from relation Decomposition: separating a relation into two by projection Join: (re)assembling two relations Whenever a row from R1 and a row from R2 have the same value for some atts A, join together to fo
17、rm a row of R3If exactly the original rows are reproduced by joining the relations, then the decomposition was lossless We join on the attributes R1 and R2 have in common (As) If it cant, the decomposition was lossy,M.P. Johnson, DBMS, Stern/NYU, Spring 2008,19,A decomposition is lossless if we can
18、recover:R(A,B,C)R1(A,B) R2(A,C)R(A,B,C) should be the same as R(A,B,C),R is in general larger than R. Must ensure R = R,Decompose,Recover,Lossless Decompositions,Lossless Decompositions,M.P. Johnson, DBMS, Stern/NYU, Spring 2008,20,Lossless decomposition,Sometimes the same set of data is reproduced:
- 1.请仔细阅读文档,确保文档完整性,对于不预览、不比对内容而直接下载带来的问题本站不予受理。
- 2.下载的文档,不会出现我们的网址水印。
- 3、该文档所得收入(下载+内容+预览)归上传者、原创作者;如果您是本文档原作者,请点此认领!既往收益都归您。
下载文档到电脑,查找使用更方便
2000 积分 0人已下载
下载 | 加入VIP,交流精品资源 |
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- C200046DATABASEMANAGEMENTSYSTEMSLECTURE5PPT
