Survey
* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project
CS 3630 Database Design and Implementation Design Methodology Three main phases 1. Conceptual database design Understanding client data E-R (EER) Model Contract between clients and designers E-R Model could be used for any database system 2. Logical database design Step1: Mapping E-R Model to (relational) database schema Step2: Normalization 3. Physical database design 2 Normalization Relational Database A set of normalized relations. Normalization To get desired performance Data consistency 1NF, 2NF, 3NF, BCNF, 4NF and higher normal forms We stop at BCNF 3 Example: DreamHome Table schemas (after mapping): Staff (Sno, Name, Address, Phone, Bno, BAddress, BPhone) 4 Problems Staff (Sno, Name, Address, Phone, Bno, BAddress, BPhone) Redundancy and Inconsistency Waste space : for each staff, store BAddress and BPhone Extra work on insertion: insert staff requires insertion of branch Extra work on updating: change BPhone, all staff in the branch Inconsistent data : when inserting and updating Sno Name Address Phone Bno Baddress BPhone S001 . . . . . . . . . . . . B20 20 main st, Platteville, WI 53818 348-8815 S012 . . . . . . . . . . . . B20 20 main st, Platteville, WI 53818 348-8815 S032 . . . . . . . . . . . . B20 20 main st, Platteville, WI 53818 348-8815 S034 . . . . . . . . . . . . B20 20 main st, Platteville, WI 53818 348-8825 S033 . . . . . . . . . . . . B20 25 main st, Platteville, WI 53818 348-8815 5 Example: DreamHome Table schemas Staff_and_Branch (Sno, Name, Address, Phone, Bno, BAddress, BPhone) Major Issue Data Redundancy Data Inconsistency Should be Staff (Sno, Name, Address, Phone, Bno) Branch (Bno, Address, Phone) Normalization! Functional Dependency! 6 Functions A function is a mapping y = f(x) y1 = f(x1) y2 = f(x2) If x1 = x2 Then y1 = y2 If x1 != x2 Then y1 != y2 YES! NO! 7 Examples Example 1 y = f(x) = x2 f(2) = f(-2) Is it possible that f(v1) != f(v2), but v1 = v2? NO! Example 2 y = g(x) = x2 - 5x + 6 y1 = g(2) = 0 y2 = g(3) = 0 Is it possible that g(u1) != g(u2), but u1 = u2? NO! 8 Functions y = f(x) y1 = f(x1) y2 = f(x2) x1 = x2 y1 = y2 True Same x value, then same y value. False x1 != x2 y1 != y2 True False Different x values, then same or different y values. Is it possible that val1 = val2 but f(val1) != f(val2) NO! Not a function! 9 Functional Dependency Table schema (DBDL) from E-R Model R (A, B, C, D, E, F) PK: A AK: B, C FK: C references R1 Functional Dependency: BD For any two records of R Same B value Same D value Different B values Same or different D values (We don’t care!) D = f(B) No such a function to calculate the value of D from that of B! 10 Example Staff (Sno, Name, Address, Bno, BAddress) PK: Sno AK: None FK: None FD: ??? 11 Example Staff (Sno, Name, Address, Bno, BAddress) FD: Sno Name Address Name Name Address Bno BAddress BAddress Bno Sno Name Address Bno BAddress S001 J. Clifton 102 main B01 1 westhill S002 M. Smith 102 main B02 3 easttown S013 M. Smith 20 main B01 1 westhill 12 Functional Dependency R (A, B, C, D, E, F) PK: A AK: B, C FK: C references R1 Functional Dependencies: BD For any two records of R Same B value Same D value Different B values Same or different D values (We don’t care!) B D not true Find two records of R Same B value Different D values (val1 = val2 but f(val1) != f(val2)) 13 Example Property (Pno, Address, Type, Ono, Oname) PK: Pno AK: Address FK: Ono references Owner FD: ??? 14 Example Property (Pno, Address, Type, Ono, Oname) Pno All Address All Ono All Ono OName OName Ono Pno Address Type YES YES NO YES NO Ono OName P001 1 Moonnite House O01 J. Clifton P002 3 Sunny House O02 M. Smith P013 9 S. Drive, U22 Aparts O03 J. Clifton P014 9 S. Drive, U15 Aparts O02 M. Smith 15 Example A 10 20 10 30 10 30 B X X Y Y Y X C 200 300 200 200 200 100 D CS CS SE SE CS CS AC? Yes B D? NO Same value implies same value Different values? We do not care! A C? B D? 16 Example A 10 20 10 30 10 10 30 20 B X X Y Y Y V Z W C 200 300 200 200 200 250 ? ? D CS SE CS CS CS XX EE CJ AC? Possible B D? NO Business rules! Must be true for all table instances! Must be part of table schema and apply to all table instances! Not just from some table instances! Checking data entry if A C is true! 17 Functional Dependency Definition Assume A and B are attributes of a table R. A B (B is functionally dependent on A) If each value of A in R is associated with exactly one value of B in R. A is called Determinant. Any two records of R If they agree on A (have the same value on A), Then they will agree on B (have the same value on B). If they have different values on A, Then they may have different values or the same value on B. B = f(A) 18 Assignment 5-1 Due Friday, February 24, by 5 PM Friday will cover all materials for A5-1 19 Assignment 4 Due February 22 By Noon. 20