Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS 3630 Database Design and Implementation. 2 Design Methodology Three main phases 1.Conceptual database design Understanding client data E-R (EER) Model.

Similar presentations


Presentation on theme: "CS 3630 Database Design and Implementation. 2 Design Methodology Three main phases 1.Conceptual database design Understanding client data E-R (EER) Model."— Presentation transcript:

1 CS 3630 Database Design and Implementation

2 2 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

3 3 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

4 4 Example: DreamHome Table schemas (after mapping): Staff (Sno, Name, Address, Phone, Bno) Branch (Bno, Address, Phone) Another Approach: Staff_and_Branch (Sno, Name, Address, Phone, Bno, BAddress, BPhone)

5 5 Problems Staff_and_Branch (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 SnoNameAddressPhoneBnoBaddressBPhone S001.. B2020 main st, Platteville, WI 53818348-8815 S012.. B2020 main st, Platteville, WI 53818348-8815 S032.. B2020 main st, Platteville, WI 53818348-8815 S034.. B2020 main st, Platteville, WI 53818348-8825 S033.. B2025 main st, Platteville, WI 53818348-8815

6 6 Example: DreamHome Table schemas Staff (Sno, Name, Address, Phone, Bno) Branch (Bno, Address, Phone) Another Approach: Staff_and_Branch (Sno, Name, Address, Phone, Bno, BAddress, BPhone) Major Issue Data Redundancy Data Inconsistency Normalization! Functional Dependency!

7 7 Functions A function is a mapping y = f(x) y1 = f(x1) y2 = f(x2) If x1 != x2 Then y1 != y2 NO! If x1 = x2 Then y1 = y2 YES!

8 8 Examples Example 1 y = f(x) = x 2 f(2) = f(-2) Is it possible that f(v1) != f(v2), but v1 = v2? NO! Example 2 y = g(x) = x 2 - 5x + 6 y1 = g(2) = 0 y2 = g(3) = 0 Is it possible that g(u1) != g(u2), but u1 = u2? NO!

9 9 Functions y = f(x) y1 = f(x1) y2 = f(x2) x1 = x2  y1 = y2 TrueFalse Same x value, then same y value. x1 != x2  y1 != y2 TrueFalse Different x values, then same or different y values. Is it possible that val1 = val2 but f(val1) != f(val2) NO! Not a function!

10 10 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: B  D 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!

11 11 Example Staff_and_Branch (Sno, Name, Address, Bno, BAddress) PK: Sno AK: None FK: None FD: ???

12 12 Example Staff_and_Branch (Sno, Name, Address, Bno, BAddress) FD: Sno  Name(YES!) Address  Name(NO!) Name  Address(NO!) Bno  BAddress(YES!) BAddress  Bno(YES!) SnoNameAddressBnoBAddress S001J. Clifton102 mainB011 westhill S002M. Smith102 mainB023 easttown S013M. Smith20 mainB011 westhill

13 13 Functional Dependency R (A, B, C, D, E, F) PK: A AK: B, C FK: C references R1 Functional Dependencies: B  D 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))

14 14 Example Property (Pno, Address, Type, Ono, Oname) PK: Pno AK: Address FK: Ono references Owner FD: ???

15 15 Example Property (Pno, Address, Type, Ono, Oname) Pno  All(YES!) Address  All(YES!) Ono  All(NO!) Ono  OName(YES!) OName  Ono(NO!) PnoAddressTypeOnoOName P0011 MoonniteHouseO01J. Clifton P0023 SunnyHouseO02M. Smith P0139 S. Drive, U22ApartsO03J. Clifton P0149 S. Drive, U15ApartsO02M. Smith

16 16 Example A B C D 10 X 200 CS 20 X 300 CS 10 Y 200 SE 30 Y 200 SE 10 Y 200 CS 30 X 100 CS A  C ? Yes B  D? NO Same value implies same value Different values? We do not care! A  C? B  D?

17 17 Example A B C D 10 X 200 CS 20 X 300 SE 10 Y 200 CS 30 Y 200 CS 10 Y 200 CS 10 V 250 XX 30 Z ? EE 20 W ? CJ A  C ? 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!

18 18 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)

19 Schedule Assignment 5-1 Due Wednesday, February 25 19


Download ppt "CS 3630 Database Design and Implementation. 2 Design Methodology Three main phases 1.Conceptual database design Understanding client data E-R (EER) Model."

Similar presentations


Ads by Google