CMPE/SE 131 Software Engineering March 9 Class Meeting

Slides:



Advertisements
Similar presentations
IS605/606: Information Systems Instructor: Dr. Boris Jukic
Advertisements

CS 185C/286: The History of Computing October 31 Class Meeting Department of Computer Science San Jose State University Fall 2011 Instructor: Ron Mak
Relational Model Stores data as tables –Each column contains values about the same attribute –Each column has a distinct name –Each row contains values.
Chapter 4 Relational Databases Copyright © 2012 Pearson Education, Inc. publishing as Prentice Hall 4-1.
Chapter 4 Relational Databases Copyright © 2012 Pearson Education 4-1.
Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall 9.1.
CS 160: Software Engineering October 8 Class Meeting
MIS 385/MBA 664 Systems Implementation with DBMS/ Database Management Dave Salisbury ( )
Chapter 1 Overview of Database Concepts Oracle 10g: SQL
1 Chapter 1 Overview of Database Concepts. 2 Chapter Objectives Identify the purpose of a database management system (DBMS) Distinguish a field from a.
Concepts and Terminology Introduction to Database.
Lecture 2 An Overview of Relational Database IST 318 – DB Admin.
CMPE 226 Database Systems September 16 Class Meeting Department of Computer Engineering San Jose State University Fall 2015 Instructor: Ron Mak
CS 174: Web Programming September 23 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
CS 174: Web Programming September 21 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
CS 160: Software Engineering October 6 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak
Chapter 1Introduction to Oracle9i: SQL1 Chapter 1 Overview of Database Concepts.
1 © Prentice Hall, 2002 Chapter 5: Logical Database Design and the Relational Model Modern Database Management 6 th Edition Jeffrey A. Hoffer, Mary B.
CMPE 226 Database Systems October 7 Class Meeting Department of Computer Engineering San Jose State University Fall 2015 Instructor: Ron Mak
CS 174: Web Programming October 14 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
The relational model A data model (in general) : Integrated collection of concepts for describing data (data requirements). Relational model was introduced.
BSA206 Database Management Systems Lecture 2: Introduction to Oracle / Overview of Database Concepts.
1 ER Modeling BUAD/American University Mapping ER modeling to Relationships.
Understand Primary, Foreign, and Composite Keys Database Administration Fundamentals LESSON 4.2.
© 2009 Pearson Education, Inc. Publishing as Prentice Hall 1 Chapter 5 (Part a): Logical Database Design and the Relational Model Modern Database Management.
Chapter 3: Relational Databases
Lecture 4: Logical Database Design and the Relational Model 1.
CS 160 and CMPE/SE 131 Software Engineering March 10 Class Meeting Department of Computer Science Department of Computer Engineering San José State University.
CS 160 and CMPE/SE 131 Software Engineering March 8 Class Meeting Department of Computer Science Department of Computer Engineering San José State University.
CS 160 and CMPE/SE 131 Software Engineering March 15 Class Meeting Department of Computer Science Department of Computer Engineering San José State University.
CMPE 226 Database Systems April 12 Class Meeting Department of Computer Engineering San Jose State University Spring 2016 Instructor: Ron Mak
CS 157B: Database Management Systems II January 23 Class Meeting Department of Computer Science San Jose State University Spring 2013 Instructor: Ron Mak.
IT 5433 LM3 Relational Data Model. Learning Objectives: List the 5 properties of relations List the properties of a candidate key, primary key and foreign.
CSIS 115 Database Design and Applications for Business
Logical Database Design and the Rational Model
CMPE Database Systems Workshop June 12 Class Meeting
Entity- Relationship (ER) Model
Chapter 4 Logical Database Design and the Relational Model
Chapter 4: Logical Database Design and the Relational Model
CHAPTER 7 DATABASE ACCESS THROUGH WEB
Chapter 6 - Database Implementation and Use
Chapter 5: Logical Database Design and the Relational Model
Tables and Their Characteristics
Quiz Questions Q.1 An entity set that does not have sufficient attributes to form a primary key is a (A) strong entity set. (B) weak entity set. (C) simple.
Chapter 12 Information Systems.
Lecture 2 The Relational Model
Chapter 4 Relational Databases
Lecture # 13 (After 1st Exam)
Translation of ER-diagram into Relational Schema
CMPE 226 Database Systems February 21 Class Meeting
CS 174: Server-Side Web Programming February 12 Class Meeting
Chapter 9 Designing Databases
CS 174: Server-Side Web Programming February 14 Class Meeting
CMPE 226 Database Systems April 11 Class Meeting
Chapter 4 The Relational Model Pearson Education © 2009.
Chapter 4 The Relational Model Pearson Education © 2009.
Teaching slides Chapter 8.
Chapter 4 The Relational Model Pearson Education © 2009.
בסיסי נתונים - מצגת ההרצאה - 1.
CHAPTER 4: LOGICAL DATABASE DESIGN AND THE RELATIONAL MODEL
The Relational Model Transparencies
Chapter 4 The Relational Model Pearson Education © 2009.
Review of Week 1 Database DBMS File systems vs. database systems
Chapter 4 The Relational Model Pearson Education © 2009.
Chengyu Sun California State University, Los Angeles
DBMS ER-Relational Mapping
A Very Brief Introduction to Relational Databases
Chapter 4 The Relational Model Pearson Education © 2009.
Review #1 Intro stuff What is a database, 4 parts, 3 users, etc.
CMPE/SE 131 Software Engineering March 7 Class Meeting
Presentation transcript:

CMPE/SE 131 Software Engineering March 9 Class Meeting Department of Computer Engineering San José State University Spring 2017 Instructor: Ron Mak www.cs.sjsu.edu/~mak

Conceptual Database Model Visualize the requirements. Use a conceptual data modeling technique. Example: Entity-relationship (ER) modeling Implementation independent: No dependencies on the logic of a particular database management system (DBMS). Example DBMS: Oracle, MySQL, etc. Blueprint for the logical model.

Logical Database Model Create the relational database model as the logical model. It’s usually straightforward to map an ER model to a relational model.

Physical Database Model The physical model is the actual database implementation. Use relational DBMS (RDBMS) software. Structured Query Language (SQL) commands to create, delete, modify, and query database structures.

An Example ER Diagram Conceptual model Database Systems by Jukić, Vrbsky, & Nestorov Pearson 2014 ISBN 978-0-13-257567-6

Another Example ER Diagram Conceptual model Database Systems by Jukić, Vrbsky, & Nestorov Pearson 2014 ISBN 978-0-13-257567-6

Logical Database Model Map the ER diagram to a logical model represented as a relational schema. Database Systems by Jukić, Vrbsky, & Nestorov Pearson 2014 ISBN 978-0-13-257567-6

Conditions for a Table to be a Relation Each column must have a name. Within a table, each column name must be unique. All values in each column must be from the same (predefined) domain. Within a table, each row must be unique. Within each row, each value in each column must be single-valued. Multiple values of the content represented by the column are not allowed in any rows of the table.

Relational vs. Non-Relational Tables Database Systems by Jukić, Vrbsky, & Nestorov Pearson 2014 ISBN 978-0-13-257567-6

Additional Properties for a Relational Table The order of columns is irrelevant. The order of rows is irrelevant.

Primary Key Each relation must have a primary key. A column or set of columns whose value uniquely identifies each row. Underline the primary key of the relational table. Database Systems by Jukić, Vrbsky, & Nestorov Pearson 2014 ISBN 978-0-13-257567-6

Mapping Entities Conceptual Physical Logical Database Systems by Jukić, Vrbsky, & Nestorov Pearson 2014 ISBN 978-0-13-257567-6

Mapping Entities, cont’d Conceptual Physical Logical Attribute with a composite primary key. Database Systems by Jukić, Vrbsky, & Nestorov Pearson 2014 ISBN 978-0-13-257567-6

Mapping Entities, cont’d Conceptual Physical Logical Entity with an optional attribute. Database Systems by Jukić, Vrbsky, & Nestorov Pearson 2014 ISBN 978-0-13-257567-6

Entity Integrity Constraint No primary key column of a relational table can have null (empty) values. Database Systems by Jukić, Vrbsky, & Nestorov Pearson 2014 ISBN 978-0-13-257567-6

Entity Integrity Constraint, cont’d Database Systems by Jukić, Vrbsky, & Nestorov Pearson 2014 ISBN 978-0-13-257567-6

Foreign Keys A foreign key is a column in a table that refers to a primary key column in another table. In a relational schema, draw an arrow from the foreign key to the corresponding primary key.

Mapping 1:M Relationships Conceptual Mandatory participation on both sides. Logical The foreign key on the M side of the 1:M relationship corresponds to the primary key on the 1 side. Physical Database Systems by Jukić, Vrbsky, & Nestorov Pearson 2014 ISBN 978-0-13-257567-6

Mapping 1:M Relationships, cont’d Conceptual Logical Optional participation on the 1 side. Physical Database Systems by Jukić, Vrbsky, & Nestorov Pearson 2014 ISBN 978-0-13-257567-6

Mapping 1:M Relationships, cont’d Conceptual Logical Optional participation on the M side. Physical Database Systems by Jukić, Vrbsky, & Nestorov Pearson 2014 ISBN 978-0-13-257567-6

Mapping 1:M Relationships, cont’d Conceptual Logical Rename a foreign key to better reflect the role of a relationship. Physical Database Systems by Jukić, Vrbsky, & Nestorov Pearson 2014 ISBN 978-0-13-257567-6

Mapping M:N Relationships Use the bridge relation BELONGSTO with two foreign keys. AKA: linking table join table Conceptual Logical Physical Database Systems by Jukić, Vrbsky, & Nestorov Pearson 2014 ISBN 978-0-13-257567-6

Mapping M:N Relationships, cont’d Conceptual Relationship with an attribute. Logical Physical Database Systems by Jukić, Vrbsky, & Nestorov Pearson 2014 ISBN 978-0-13-257567-6

Mapping 1:1 Relationships Map 1:1 relationships similarly to 1:M relationships. One table will have a foreign key pointing to the primary key of the other table. It can be an arbitrary choice of which table has the foreign key. Make the choice that is most intuitive or efficient.

Mapping 1:1 Relationships, cont’d Conceptual Logical Table VEHICLE has the foreign key. Physical Database Systems by Jukić, Vrbsky, & Nestorov Pearson 2014 ISBN 978-0-13-257567-6

Referential Integrity Constraint The value of a foreign key must either: Match one of the values of the primary key in the referred table. Be null. Database Systems by Jukić, Vrbsky, & Nestorov Pearson 2014 ISBN 978-0-13-257567-6

Mapping Example: ER Diagram Conceptual Data Model Database Systems by Jukić, Vrbsky, & Nestorov Pearson 2014 ISBN 978-0-13-257567-6

Mapping Example: Relational Schema Logical Data Model Database Systems by Jukić, Vrbsky, & Nestorov Pearson 2014 ISBN 978-0-13-257567-6

Mapping Example: Sample Data Physical Data Model Database Systems by Jukić, Vrbsky, & Nestorov Pearson 2014 ISBN 978-0-13-257567-6

School Database Example Initial version Each table has a primary key (PK) field whose value in each record uniquely identifies that record. Student Id Name Teacher_id_1 Teacher_id_2 Teacher_id_3 1001 Doe, John 7003 7012 7008 1005 Novak, Tim null 1009 Klein, Leslie 1014 Jane, Mary 7051 1021 Smith, Kim Student id name which teachers Teacher which classes taught Class class code subject name class room number PK Teacher Id Name Class_code Subject Room 7003 Rogers, Tom 926 Java programming 101 7008 Thompson, Art 908 Data structures 114 7012 Lane, John 951 Software engineering 210 974 Operating systems 109 7051 Flynn, Mabel 931 Compilers 222 John Lane teaches two classes. PK

Normalization Relational tables need to be normalized. Improve the stability of the model. More resilient to change. Faster record insertions and updates. Improve data quality. There are six normal forms, but we will only consider the first two. Each normal form includes the lower normal forms. Example: A database in second normal form is also in first normal form.

First Normal Form (1NF) Separate multi-valued data elements. Break the name fields into last name and first name fields. Student Id Name Teacher_id_1 Teacher_id_2 Teacher_id_3 1001 Doe, John 7003 7012 7008 1005 Novak, Tim null 1009 Klein, Leslie 1014 Jane, Mary 7051 1021 Smith, Kim Id Last First Teacher_id_1 Teacher_id_2 Teacher_id_3 1001 Doe John 7003 7012 7008 1005 Novak Tim null 1009 Klein Leslie 1014 Jane Mary 7051 1021 Smith Kim Teacher Id Name Class_code Subject Room 7003 Rogers, Tom 926 Java programming 101 7008 Thompson, Art 908 Data structures 114 7012 Lane, John 951 Software engineering 210 974 Operating systems 109 7051 Flynn, Mabel 931 Compilers 222 Id Last First Class_code Subject Room 7003 Rogers Tom 926 Java programming 101 7008 Thompson Art 908 Data structures 114 7012 Lane John 951 Software engineering 210 974 Operating systems 109 7051 Flynn Mabel 931 Compilers 222

First Normal Form, cont’d Move repeating data elements to a new table. Student_Teacher Student_id Teacher_id 1001 7003 7012 7008 1005 1014 7051 1021 Student Id Last First Teacher_id_1 Teacher_id_2 Teacher_id_3 1001 Doe John 7003 7012 7008 1005 Novak Tim null 1009 Klein Leslie 1014 Jane Mary 7051 1021 Smith Kim Id Last First 1001 Doe John 1005 Novak Tim 1009 Klein Leslie 1014 Jane Mary 1021 Smith Kim Linking table Teacher Id Last First Class_code Subject Room 7003 Rogers Tom 926 Java programming 101 7008 Thompson Art 908 Data structures 114 7012 Lane John 951 Software engineering 210 974 Operating systems 109 7051 Flynn Mabel 931 Compilers 222

Problem! Suppose Prof. Lane decides he doesn’t want to teach Operating Systems anymore and we delete that row. What other information do we lose as a result? We lose the fact that the class is taught in Room 109. The problem arises because the Teacher table really contains two separate sets of data: teacher data and class data. Teacher Id Last First Class_code Subject Room 7003 Rogers Tom 926 Java programming 101 7008 Thompson Art 908 Data structures 114 7012 Lane John 951 Software engineering 210 974 Operating systems 109 7051 Flynn Mabel 931 Compilers 222

Second Normal Form (2NF) Keep related data together (cohesiveness). Teacher Class Id Last First 7003 Rogers Tom 7008 Thompson Art 7012 Lane John 7051 Flynn Mabel Class_code Teacher_id Subject Room 908 7008 Data structures 114 926 7003 Java programming 101 931 7051 Compilers 222 951 7012 Software engineering 210 974 Operating systems 109 Primary key (PK) Primary key (PK) Foreign key (FK) How would you do this relation with a linking table?

Final Database Structure, cont’d Student_Class John Doe takes Java programming, software engineering, and data structures. Student_id Class_code 1001 926 951 908 1005 974 1014 931 1021 Student Id Last First 1001 Doe John 1005 Novak Tim 1009 Klein Leslie 1014 Jane Mary 1021 Smith Kim Class Teacher Code Teacher_id Subject Room 908 7008 Data structures 114 926 7003 Java programming 101 931 7051 Compilers 222 951 7012 Software engineering 210 974 Operating systems 109 Id Last First 7003 Rogers Tom 7008 Thompson Art 7012 Lane John 7051 Flynn Mabel

Final Database Structure, cont’d Student_Class The Java Programming class has John Doe and Kim Smith. Student_id Class_code 1001 926 951 908 1005 974 1014 931 1021 Student Id Last First 1001 Doe John 1005 Novak Tim 1009 Klein Leslie 1014 Jane Mary 1021 Smith Kim Class Teacher Code Teacher_id Subject Room 908 7008 Data structures 114 926 7003 Java programming 101 931 7051 Compilers 222 951 7012 Software engineering 210 974 Operating systems 109 Id Last First 7003 Rogers Tom 7008 Thompson Art 7012 Lane John 7051 Flynn Mabel

Final Database Structure, cont’d Student_Class Student_id Class_code 1001 926 951 908 1005 974 1014 931 1021 Mabel Flynn teaches compilers. Student Id Last First 1001 Doe John 1005 Novak Tim 1009 Klein Leslie 1014 Jane Mary 1021 Smith Kim Class Teacher Code Teacher_id Subject Room 908 7008 Data structures 114 926 7003 Java programming 101 931 7051 Compilers 222 951 7012 Software engineering 210 974 Operating systems 109 Id Last First 7003 Rogers Tom 7008 Thompson Art 7012 Lane John 7051 Flynn Mabel

Assignment #5 Initial draft of your Design Document. Document the design of your application. MVC architecture UML package and class diagrams UML sequence diagram Document the design of your database. Conceptual model: entity-relationship (ER) diagram Logical model: relational schema