24
October 22, 2017 Sam Siewert CS317 File and Database Systems Lecture 9 – Conceptual, Logical, and Physical DBMS Design http://dev.mysql.com/downloads/workbench

CS317 File and Database Systemsmercury.pr.erau.edu/~siewerts/cs317/documents/Lectures/...S1024 Helen Pearson P108 Ian MacKay 9/12/13, 10:00 S10 1068 C1025 28 White T H4 Glasgow S1024

  • Upload
    others

  • View
    6

  • Download
    0

Embed Size (px)

Citation preview

Page 1: CS317 File and Database Systemsmercury.pr.erau.edu/~siewerts/cs317/documents/Lectures/...S1024 Helen Pearson P108 Ian MacKay 9/12/13, 10:00 S10 1068 C1025 28 White T H4 Glasgow S1024

October 22, 2017 Sam Siewert

CS317 File and Database Systems

Lecture 9 – Conceptual, Logical, and Physical DBMS Design

http://dev.mysql.com/downloads/workbench

Page 2: CS317 File and Database Systemsmercury.pr.erau.edu/~siewerts/cs317/documents/Lectures/...S1024 Helen Pearson P108 Ian MacKay 9/12/13, 10:00 S10 1068 C1025 28 White T H4 Glasgow S1024

Reminders Assignment #4 Due Friday

Assignment #3 Being Graded Assignment #5, Physical DB Design Assignment #6, DBMS Project of Your Interest – FINAL ORAL PRESENTATION – Design Schema for DBMS project in a small team

Logical design focus Normalization Physical is MySQL on PRClab

– Combine Network Applications with DBMS in C/C++, JDBC, or Python - http://www.mysql.com/products/connector/

– Add Stored Programs and Triggers – Add Views – Create Transactions where needed

Sam Siewert 2

Page 3: CS317 File and Database Systemsmercury.pr.erau.edu/~siewerts/cs317/documents/Lectures/...S1024 Helen Pearson P108 Ian MacKay 9/12/13, 10:00 S10 1068 C1025 28 White T H4 Glasgow S1024

Normalization Exercise

1. What is current Normalization Level?

2. What are Functional Dependencies? Full? Partial?

3. Provide 2NF Version

4. Are there any Transitive Dependencies?

5. Provide 3NF Version and Explain

Sam Siewert 3

staffNo dentistName patNo patName appDate, appTime surgeryRoomNo NatInsNum contractNo hours eName hotelNo hotelLocS1011 Tony Smith P100 Gillian White 9/12/13, 10:00 S15 1135 C1024 16 Smith J H25 East KilbrideS1011 Tony Smith P105 Jill Bell 9/12/13, 12:00 S15 1057 C1024 24 Hocine D H25 East KilbrideS1024 Helen Pearson P108 Ian MacKay 9/12/13, 10:00 S10 1068 C1025 28 White T H4 GlasgowS1024 Helen Pearson P108 Ian MacKay 9/14/13, 14:00 S10 1135 C1025 15 Smith J H4 GlasgowS1032 Robin Plevin P105 Jill Bell 9/14/13, 16:30 S15S1032 Robin Plevin P110 John Walker 9/15,13, 18:00 S13

Team A - 14.19 Team B - 14.20

Page 4: CS317 File and Database Systemsmercury.pr.erau.edu/~siewerts/cs317/documents/Lectures/...S1024 Helen Pearson P108 Ian MacKay 9/12/13, 10:00 S10 1068 C1025 28 White T H4 Glasgow S1024

Normalization

Sam Siewert 4

staffNo dentistName patNo patName appDate, appTime surgeryRoomNo NatInsNum contractNo hours eName hotelNo hotelLocS1011 Tony Smith P100 Gillian White 9/12/13, 10:00 S15 1135 C1024 16 Smith J H25 East KilbrideS1011 Tony Smith P105 Jill Bell 9/12/13, 12:00 S15 1057 C1024 24 Hocine D H25 East KilbrideS1024 Helen Pearson P108 Ian MacKay 9/12/13, 10:00 S10 1068 C1025 28 White T H4 GlasgowS1024 Helen Pearson P108 Ian MacKay 9/14/13, 14:00 S10 1135 C1025 15 Smith J H4 GlasgowS1032 Robin Plevin P105 Jill Bell 9/14/13, 16:30 S15S1032 Robin Plevin P110 John Walker 9/15,13, 18:00 S13

Step 1 UNF - repeating groups in appDate, appTime Step 1 1 NF due to hazards, e.g. modify hotelLoc

Step 2 FD1 staffNo, appDate, appTime -> patNo, patName Step 2 FD1 NatInsNum, contractNo -> hoursFD2 staffNo -> dentistName FD2 NatInsNum -> eNameFD3 patNo -> patName, surgeryNo FD3 contractNo -> hotelNo, hotelLocFD4 staffNo, appDate -> surgeryRoomNo FD4 hotelNo -> hotelLocFD5 patNo, aTime, aDate -> staffNo, dentistName

staffNo appDate appTime patNo patName NatInsNum contractNo hours

staffNo appDate urgeryRoomNo contractNo hotelNo hotelLoc

staffNo dentistName NatInsNum eName

Step 4 FD3 patNo -> patName, surgeryNo Step 4 FD4 hotelNo -> hotelLoc

staffNo appDate appTime patNo NatInsNum contractNo hours

staffNo appDate urgeryRoomNo contractNo hotelNo

staffNo dentistName NatInsNum eName

patNo patName hotelNo hotelLoc

Team A - 14.19 Team B - 14.20

Step 3 - 2NF Step 3 - 2NF

Step 5 -3NF Step 5 -3NF

Page 5: CS317 File and Database Systemsmercury.pr.erau.edu/~siewerts/cs317/documents/Lectures/...S1024 Helen Pearson P108 Ian MacKay 9/12/13, 10:00 S10 1068 C1025 28 White T H4 Glasgow S1024

DBMS Design in 10 Steps DBMS Design - Decomposition 1. Conceptual Design – Analysis, Centralized or View Integration 2. Build and Validate Logical Data Model – ER/EER,

Normalization, Schema Prototype (Workbench) 3. Translate Logical Data Model for Target DBMS (MySQL) 4. Design File Organization (or Block) and Indexing 5. Triggers and SQL/PSM for Referential Integrity 6. User View Design (Lossless Join Verification) 7. Security 8. Transactions for Complex Updates 9. Redundancy (RTO/RPO and RAID) 10. Connectors for App Interfaces

Covered, To be covered

Sam Siewert 5

Page 6: CS317 File and Database Systemsmercury.pr.erau.edu/~siewerts/cs317/documents/Lectures/...S1024 Helen Pearson P108 Ian MacKay 9/12/13, 10:00 S10 1068 C1025 28 White T H4 Glasgow S1024

Goals for This Week Wrap-Up DBMS Conceptual Design Wrap-Up DBMS Logical Design – Examine Use of MySQL Workbench to Go Between EER and

Schemas – Forward Engineer – Reverse Engineer – Workbench Tutorial -

https://www.youtube.com/watch?v=X_umYKqKaF0

Introduce DBMS Physical Design – Introduction to B and B+ Trees – Discussion of MySQL Physical Layers – In-Depth Study of B and B+ Trees Next Week

Sam Siewert 6

Page 7: CS317 File and Database Systemsmercury.pr.erau.edu/~siewerts/cs317/documents/Lectures/...S1024 Helen Pearson P108 Ian MacKay 9/12/13, 10:00 S10 1068 C1025 28 White T H4 Glasgow S1024

7

Using pathways to check that the conceptual model supports the user

transactions [A2.2, A-5]

Page 8: CS317 File and Database Systemsmercury.pr.erau.edu/~siewerts/cs317/documents/Lectures/...S1024 Helen Pearson P108 Ian MacKay 9/12/13, 10:00 S10 1068 C1025 28 White T H4 Glasgow S1024

Transaction Checks DML – Update/Delete Query Transactions Can all be Implemented with core SQL SQL/PSM JBDC or C/C++ Embedding - MySQL Connector

Sam Siewert 8

Page 9: CS317 File and Database Systemsmercury.pr.erau.edu/~siewerts/cs317/documents/Lectures/...S1024 Helen Pearson P108 Ian MacKay 9/12/13, 10:00 S10 1068 C1025 28 White T H4 Glasgow S1024

Going from Paper Design to Schemas Relational Models, ER, and EER on Paper are Helpful, but How Do We Transition to a Schema we Can Test? Workbench can be Downloaded and Installed on Windows, Max OS-X, Linux - http://dev.mysql.com/downloads/workbench Enter Design as an EER using Graphical Workbench

Sam Siewert 9

Generate SQL DDL Schema When Ready…

Page 10: CS317 File and Database Systemsmercury.pr.erau.edu/~siewerts/cs317/documents/Lectures/...S1024 Helen Pearson P108 Ian MacKay 9/12/13, 10:00 S10 1068 C1025 28 White T H4 Glasgow S1024

Reverse Engineer Existing Schema to EER DreamHome v. 1.0 – 6 Tables, Related by Foreign Keys Not Taking Advantage of EER, but Can Update Model and Export, Re-Import Data to Improve

Sam Siewert 10

Page 11: CS317 File and Database Systemsmercury.pr.erau.edu/~siewerts/cs317/documents/Lectures/...S1024 Helen Pearson P108 Ian MacKay 9/12/13, 10:00 S10 1068 C1025 28 White T H4 Glasgow S1024

Sakila EER Model

Sam Siewert 11

Tables, Views, SQL/PSM Routines, Triggers in EER

Page 12: CS317 File and Database Systemsmercury.pr.erau.edu/~siewerts/cs317/documents/Lectures/...S1024 Helen Pearson P108 Ian MacKay 9/12/13, 10:00 S10 1068 C1025 28 White T H4 Glasgow S1024

Sakila Example Tables, Views, PSM Routines, Triggers Models Relations Between Entities [Tables] and Includes Operations [Routines] More Sophisticated Design and Schema that Matches

Sam Siewert 12

Page 13: CS317 File and Database Systemsmercury.pr.erau.edu/~siewerts/cs317/documents/Lectures/...S1024 Helen Pearson P108 Ian MacKay 9/12/13, 10:00 S10 1068 C1025 28 White T H4 Glasgow S1024

Reverse Engineer Differences The Forward/Reverse Engineering is Not Perfect, but Not Bad SQL Generation from Pictures, Picture Generation from SQL Much like at GUI Code Generator Issue is Sync Between Design and SQL Sam Siewert 13

Page 14: CS317 File and Database Systemsmercury.pr.erau.edu/~siewerts/cs317/documents/Lectures/...S1024 Helen Pearson P108 Ian MacKay 9/12/13, 10:00 S10 1068 C1025 28 White T H4 Glasgow S1024

Recall DreamHome v. 2.0 ER Design Entities, Attributes, Keys, 1:1, 1:*, *:1 Relations Features PK and FK Attributes

Sam Siewert 14

Page 15: CS317 File and Database Systemsmercury.pr.erau.edu/~siewerts/cs317/documents/Lectures/...S1024 Helen Pearson P108 Ian MacKay 9/12/13, 10:00 S10 1068 C1025 28 White T H4 Glasgow S1024

Improvements to DreamHome v. 1.0 Connections 1:n Made Via PKs Note InnoDB Physical Engine Required for FKs Improve Model and Schema

Sam Siewert 15

FKs Require InnoDB, MyISAM default [Many options – MEMORY, FEDERATED, ScaleDB…]

Page 16: CS317 File and Database Systemsmercury.pr.erau.edu/~siewerts/cs317/documents/Lectures/...S1024 Helen Pearson P108 Ian MacKay 9/12/13, 10:00 S10 1068 C1025 28 White T H4 Glasgow S1024

DreamHome v. 1.0 EER See if We Can Improve PK, FK and Normalization

Sam Siewert 16

Page 17: CS317 File and Database Systemsmercury.pr.erau.edu/~siewerts/cs317/documents/Lectures/...S1024 Helen Pearson P108 Ian MacKay 9/12/13, 10:00 S10 1068 C1025 28 White T H4 Glasgow S1024

Check Schema and Add Test Data Review Schema

Sam Siewert 17

Page 18: CS317 File and Database Systemsmercury.pr.erau.edu/~siewerts/cs317/documents/Lectures/...S1024 Helen Pearson P108 Ian MacKay 9/12/13, 10:00 S10 1068 C1025 28 White T H4 Glasgow S1024

DreamHome v. 2.0 Global EER

Sam Siewert 18

Page 19: CS317 File and Database Systemsmercury.pr.erau.edu/~siewerts/cs317/documents/Lectures/...S1024 Helen Pearson P108 Ian MacKay 9/12/13, 10:00 S10 1068 C1025 28 White T H4 Glasgow S1024

Equivalent Using DH v. 1.0 Adapted

Sam Siewert 19

Page 20: CS317 File and Database Systemsmercury.pr.erau.edu/~siewerts/cs317/documents/Lectures/...S1024 Helen Pearson P108 Ian MacKay 9/12/13, 10:00 S10 1068 C1025 28 White T H4 Glasgow S1024

20

Step 2 Build and Validate Logical Data Model

Step 2.1 Derive relations for logical data model – To create relations for the logical data model to

represent the entities, relationships, and attributes that have been identified [Enter into MySQL Workbench]

Step 2.2 Validate relations using normalization – To validate the relations in the logical data model using

normalization [Check Functional Dependencies and Scan for Insert, Delete, Update Hazards]

– Would be Nice if MySQL Workbench had Normalization Checker – it Does Not! But, it Does Help Auto-Complete Keys

Step 2.3 Validate relations against user transactions – To ensure that the relations in the logical data model support the

required transactions [Create Views, Test Update, Delete, Insert]

Page 21: CS317 File and Database Systemsmercury.pr.erau.edu/~siewerts/cs317/documents/Lectures/...S1024 Helen Pearson P108 Ian MacKay 9/12/13, 10:00 S10 1068 C1025 28 White T H4 Glasgow S1024

21

Step 2.4 Check integrity constraints

Run Forward Engineering to Generate SQL To check integrity constraints are represented in the logical data model. This includes identifying:

Required data Attribute domain constraints Multiplicity Entity integrity Referential integrity General constraints

Page 22: CS317 File and Database Systemsmercury.pr.erau.edu/~siewerts/cs317/documents/Lectures/...S1024 Helen Pearson P108 Ian MacKay 9/12/13, 10:00 S10 1068 C1025 28 White T H4 Glasgow S1024

22

Referential integrity constraints for relations in Staff user views of

DreamHome

Page 23: CS317 File and Database Systemsmercury.pr.erau.edu/~siewerts/cs317/documents/Lectures/...S1024 Helen Pearson P108 Ian MacKay 9/12/13, 10:00 S10 1068 C1025 28 White T H4 Glasgow S1024

23

Step 2.5 Review logical data model with user

To review the logical data model with the users to ensure that they consider the model to be a true representation of the data requirements of the enterprise.

Page 24: CS317 File and Database Systemsmercury.pr.erau.edu/~siewerts/cs317/documents/Lectures/...S1024 Helen Pearson P108 Ian MacKay 9/12/13, 10:00 S10 1068 C1025 28 White T H4 Glasgow S1024

24

Step 2.6.1 Merge logical data models into a global model [OPTIONAL] Tasks typically includes:

(1) Review the names and contents of entities/relations and their candidate keys. (2) Review the names and contents of relationships/foreign keys. (3) Merge entities/relations from the local data models (4) Include (without merging) entities/relations unique to each local data model (5) Merge relationships/foreign keys from the local data models. (6) Include (without merging) relationships/foreign keys unique to each local data model. (7) Check for missing entities/relations and relationships/foreign keys. (8) Check foreign keys. (9) Check Integrity Constraints. (10) Draw the global ER/relation diagram (11) Update the documentation.