CS 160 and CMPE/SE 131 Software Engineering March 10 Class Meeting Department of Computer Science Department of Computer Engineering San José State University.

Slides:



Advertisements
Similar presentations
BUSINESS DRIVEN TECHNOLOGY Plug-In T4 Designing Database Applications.
Advertisements

Copyright © 2015 Pearson Education, Inc. Database Design Chapters 17 and
Systems Development Life Cycle
Database Design & Mapping
Databases Revision.
CS 185C/286: The History of Computing October 31 Class Meeting Department of Computer Science San Jose State University Fall 2011 Instructor: Ron Mak
© 2005 by Prentice Hall Chapter 3a Database Design Modern Systems Analysis and Design Fourth Edition Jeffrey A. Hoffer Joey F. George Joseph S. Valacich.
Relational Model Stores data as tables –Each column contains values about the same attribute –Each column has a distinct name –Each row contains values.
Entity-Relationship Model and Diagrams (continued)
APPENDIX C DESIGNING DATABASES
© 2007 by Prentice Hall (Hoffer, Prescott & McFadden) 1 Entity Relationship Diagrams (ERDs)
Chapter 3: Modeling Data in the Organization
Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall 9.1.
CS 160: Software Engineering November 10 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak
Web-Enabled Decision Support Systems
CS 160: Software Engineering October 8 Class Meeting
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.
1 ER Modeling BUAD/American University Entity Relationship (ER) Modeling.
Copyright (c) 2014 Pearson Education, Inc. Introduction to Databases.
CMPE 226 Database Systems September 9 Class Meeting Department of Computer Engineering San Jose State University Fall 2015 Instructor: Ron Mak
Concepts and Terminology Introduction to Database.
CMPE 226 Database Systems September 16 Class Meeting Department of Computer Engineering San Jose State University Fall 2015 Instructor: Ron Mak
Database Systems Lecture # 7 8 th Feb, Conceptual and Logical Design Person buys Product name pricenamessn Conceptual Model: Relational Model: (plus.
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 157B: Database Management Systems II February 6 Class Meeting Department of Computer Science San Jose State University Spring 2013 Instructor: Ron Mak.
CS 157B: Database Management Systems II February 4 Class Meeting Department of Computer Science San Jose State University Spring 2013 Instructor: Ron Mak.
Copyright 2008 McGraw-Hill Ryerson 1 TECHNOLOGY PLUG-IN T5 DESIGNING DATABASE APPLICATIONS.
McGraw-Hill/Irwin © 2008 The McGraw-Hill Companies, All Rights Reserved Plug-In T5: Designing Database Applications Business Driven Technology.
© 2011 Pearson Education, Inc. Publishing as Prentice Hall 1 Chapter 2: Modeling Data in the Organization.
CS 160: Software Engineering October 1 Class Meeting Department of Computer Science San Jose State University Fall 2014 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.
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall, modified by Dr. Lyn Mathis 5-1 David M. Kroenke’s, 10 th ed. Chapter.
Relational Database. Database Management System (DBMS)
1 Entity-Relationship Diagram. 2 Components of ERD: –Entity –Relationship –Cardinality –Attributes.
3 & 4 1 Chapters 3 and 4 Drawing ERDs October 16, 2006 Week 3.
Chapter 9: Logical Database Design and the Relational Model (ERD Mapping)
1 © Prentice Hall, 2002 Chapter 5: Logical Database Design and the Relational Model Modern Database Management 6 th Edition Jeffrey A. Hoffer, Mary B.
ENTITY RELATIONSHIP DIAGRAM ENTITY RELATIONSHIP DIAGRAM IS A SPECIALIZED GRAPHIC THAT ILLUSTRATES THE INTERRELATIONSHIPS BETWEEN ENTITIES IN A DATABASE.
Relational Theory and Design
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 4 ENTITY RELATIONSHIP (ER) MODELING Instructor Ms. Arwa Binsaleh 1.
advanced data modeling
Information Access Mgt09/12/971 Entity-Relationship Design Information Level Design.
1 ER Modeling BUAD/American University Mapping ER modeling to Relationships.
Chapter 10 Designing Databases. Objectives:  Define key database design terms.  Explain the role of database design in the IS development process. 
Understand Relational Database Management Systems Software Development Fundamentals LESSON 6.1.
Chapter 3: Modeling Data in the Organization. Business Rules Statements that define or constrain some aspect of the business Assert business structure.
Entity Relationship Diagram (ERD). Objectives Define terms related to entity relationship modeling, including entity, entity instance, attribute, relationship.
Logical Database Design and the Relational Model.
© 2009 Pearson Education, Inc. Publishing as Prentice Hall 1 Chapter 5 (Part a): Logical Database Design and the Relational Model Modern Database Management.
CMPE 226 Database Systems February 16 Class Meeting Department of Computer Engineering San Jose State University Spring 2016 Instructor: Ron Mak
Copyright © 2016 Pearson Education, Inc. Modern Database Management 12 th Edition Jeff Hoffer, Ramesh Venkataraman, Heikki Topi CHAPTER 2: MODELING DATA.
© 2009 Pearson Education, Inc. Publishing as Prentice Hall 1 Chapter 3: Modeling Data in the Organization Modern Database Management 9 th Edition Jeffrey.
Data Modeling AND ER MODELS.
Department of Mathematics Computer and Information Science1 CS 351: Database Management Systems Christopher I. G. Lanclos Chapter 4.
CS 160 and CMPE/SE 131 Software Engineering March 8 Class Meeting Department of Computer Science Department of Computer Engineering San José State University.
IS 4420 Database Fundamentals Chapter 3: Modeling Data in the Organization Leon Chen.
CS 160 and CMPE/SE 131 Software Engineering March 15 Class Meeting Department of Computer Science Department of Computer Engineering San José State University.
Rationale Databases are an integral part of an organization. Aspiring Database Developers should be able to efficiently design and implement databases.
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.
Tables and Their Characteristics
CMPE 226 Database Systems February 21 Class Meeting
CS 174: Server-Side Web Programming February 12 Class Meeting
CS 174: Server-Side Web Programming February 14 Class Meeting
CHAPTER 4: LOGICAL DATABASE DESIGN AND THE RELATIONAL MODEL
CMPE/SE 131 Software Engineering March 9 Class Meeting
CMPE/SE 131 Software Engineering March 7 Class Meeting
Presentation transcript:

CS 160 and CMPE/SE 131 Software Engineering March 10 Class Meeting Department of Computer Science Department of Computer Engineering San José State University Spring 2016 Instructor: Ron Mak

Computer Science Dept. Spring 2016: March 10 CS 160 and CMPE/SE 131: Software Engineering © R. Mak Free IDE for Ruby and Rails  RubyMine 2

Computer Science Dept. Spring 2016: March 10 CS 160 and CMPE/SE 131: Software Engineering © R. Mak 3 Conceptual Data Model Example  Student, teacher, class, and contact info entities and their attributes. Student  id  first name  last name  contact info Teacher  id  first name  last name  contact info Class  class code  subject name  classroom number  which teacher Contact info  id  address

Computer Science Dept. Spring 2016: March 10 CS 160 and CMPE/SE 131: Software Engineering © R. Mak Conceptual Model: Entities and Attributes  In an ER diagram (ERD), show an entity with a rectangle and its attributes with ovals. Underline the unique attribute. 4

Computer Science Dept. Spring 2016: March 10 CS 160 and CMPE/SE 131: Software Engineering © R. Mak Conceptual Model: Relationships  Each entity in an ER diagram must be related to at least one other entity.  Show a relationship with a diamond and connect the diamond to the entities that are part of the relationship. 5 Database Systems by Jukić, Vrbsky, & Nestorov Pearson 2014 ISBN

Computer Science Dept. Spring 2016: March 10 CS 160 and CMPE/SE 131: Software Engineering © R. Mak Relationship Cardinality  Show cardinality (how many instances of an entity) with symbols at the end of the relationship lines. Maximum symbol closest to the entity. Minimum symbol further away. Zero, one, many 6 Database Systems by Jukić, Vrbsky, & Nestorov Pearson 2014 ISBN

Computer Science Dept. Spring 2016: March 10 CS 160 and CMPE/SE 131: Software Engineering © R. Mak Relationship Cardinality, cont’d  Read each relationship in both directions in this order: rectangle diamond cardinality rectangle 7 Database Systems by Jukić, Vrbsky, & Nestorov Pearson 2014 ISBN

Computer Science Dept. Spring 2016: March 10 CS 160 and CMPE/SE 131: Software Engineering © R. Mak Types of Relationships  One-to-one (1:1)  One-to-many (1:M) 8 Database Systems by Jukić, Vrbsky, & Nestorov Pearson 2014 ISBN Each employee is allotted at most one vehicle. Each vehicle is allotted to exactly one employee. Each region has located in it at least one (i.e., many) stores.

Computer Science Dept. Spring 2016: March 10 CS 160 and CMPE/SE 131: Software Engineering © R. Mak Types of Relationships, cont’d  Many-to-many (M:N) 9 Database Systems by Jukić, Vrbsky, & Nestorov Pearson 2014 ISBN Each employee is assigned to no or several (i.e., many) projects. Each project has assigned to it at least one (i.e., many) employee.

Computer Science Dept. Spring 2016: March 10 CS 160 and CMPE/SE 131: Software Engineering © R. Mak Exact Cardinalities  Indicate exact cardinalities with parenthesized minimum and maximum values. Example: (2, 6) Use M for a non-specific minimum or maximum. 10 Database Systems by Jukić, Vrbsky, & Nestorov Pearson 2014 ISBN

Computer Science Dept. Spring 2016: March 10 CS 160 and CMPE/SE 131: Software Engineering © R. Mak Relationship Attributes  An relationship can also have attributes. 11 Database Systems by Jukić, Vrbsky, & Nestorov Pearson 2014 ISBN

Computer Science Dept. Spring 2016: March 10 CS 160 and CMPE/SE 131: Software Engineering © R. Mak Logical Database Model  Map the ER diagram to a logical model represented as a relational schema. 12 Database Systems by Jukić, Vrbsky, & Nestorov Pearson 2014 ISBN

Computer Science Dept. Spring 2016: March 10 CS 160 and CMPE/SE 131: Software Engineering © R. Mak 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. M ultiple values of the content represented by the column are not allowed in any rows of the table. 13

Computer Science Dept. Spring 2016: March 10 CS 160 and CMPE/SE 131: Software Engineering © R. Mak Relational vs. Non-Relational Tables 14 Database Systems by Jukić, Vrbsky, & Nestorov Pearson 2014 ISBN

Computer Science Dept. Spring 2016: March 10 CS 160 and CMPE/SE 131: Software Engineering © R. Mak Additional Properties for a Relational Table  The order of columns is irrelevant.  The order of rows is irrelevant. 15

Computer Science Dept. Spring 2016: March 10 CS 160 and CMPE/SE 131: Software Engineering © R. Mak 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. 16 Database Systems by Jukić, Vrbsky, & Nestorov Pearson 2014 ISBN

Computer Science Dept. Spring 2016: March 10 CS 160 and CMPE/SE 131: Software Engineering © R. Mak Mapping Entities 17 Database Systems by Jukić, Vrbsky, & Nestorov Pearson 2014 ISBN Conceptual Logical Physical

Computer Science Dept. Spring 2016: March 10 CS 160 and CMPE/SE 131: Software Engineering © R. Mak Mapping Entities, cont’d 18 Attribute with a composite primary key. Database Systems by Jukić, Vrbsky, & Nestorov Pearson 2014 ISBN Conceptual Logical Physical

Computer Science Dept. Spring 2016: March 10 CS 160 and CMPE/SE 131: Software Engineering © R. Mak Mapping Entities, cont’d 19 Entity with an optional attribute. Database Systems by Jukić, Vrbsky, & Nestorov Pearson 2014 ISBN Conceptual Logical Physical

Computer Science Dept. Spring 2016: March 10 CS 160 and CMPE/SE 131: Software Engineering © R. Mak Entity Integrity Constraint  No primary key column of a relational table can have null (empty) values. 20 Database Systems by Jukić, Vrbsky, & Nestorov Pearson 2014 ISBN

Computer Science Dept. Spring 2016: March 10 CS 160 and CMPE/SE 131: Software Engineering © R. Mak Entity Integrity Constraint, cont’d 21 Database Systems by Jukić, Vrbsky, & Nestorov Pearson 2014 ISBN

Computer Science Dept. Spring 2016: March 10 CS 160 and CMPE/SE 131: Software Engineering © R. Mak 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. 22

Computer Science Dept. Spring 2016: March 10 CS 160 and CMPE/SE 131: Software Engineering © R. Mak Mapping 1:M Relationships 23 The foreign key on the M side of the 1:M relationship corresponds to the primary key on the 1 side. Mandatory participation on both sides. Database Systems by Jukić, Vrbsky, & Nestorov Pearson 2014 ISBN Conceptual Logical Physical

Computer Science Dept. Spring 2016: March 10 CS 160 and CMPE/SE 131: Software Engineering © R. Mak Mapping 1:M Relationships, cont’d 24 Optional participation on the 1 side. Database Systems by Jukić, Vrbsky, & Nestorov Pearson 2014 ISBN Conceptual Logical Physical

Computer Science Dept. Spring 2016: March 10 CS 160 and CMPE/SE 131: Software Engineering © R. Mak Mapping 1:M Relationships, cont’d 25 Optional participation on the M side. Database Systems by Jukić, Vrbsky, & Nestorov Pearson 2014 ISBN Conceptual Logical Physical

Computer Science Dept. Spring 2016: March 10 CS 160 and CMPE/SE 131: Software Engineering © R. Mak Mapping 1:M Relationships, cont’d 26 Rename a foreign key to better reflect the role of a relationship. Database Systems by Jukić, Vrbsky, & Nestorov Pearson 2014 ISBN Conceptual Logical Physical

Computer Science Dept. Spring 2016: March 10 CS 160 and CMPE/SE 131: Software Engineering © R. Mak Mapping M:N Relationships 27 Use the bridge relation BELONGSTO with two foreign keys. AKA: linking table join table Database Systems by Jukić, Vrbsky, & Nestorov Pearson 2014 ISBN Conceptual Logical Physical

Computer Science Dept. Spring 2016: March 10 CS 160 and CMPE/SE 131: Software Engineering © R. Mak Mapping M:N Relationships, cont’d 28 Relationship with an attribute. Database Systems by Jukić, Vrbsky, & Nestorov Pearson 2014 ISBN Conceptual Logical Physical

Computer Science Dept. Spring 2016: March 10 CS 160 and CMPE/SE 131: Software Engineering © R. Mak 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. 29

Computer Science Dept. Spring 2016: March 10 CS 160 and CMPE/SE 131: Software Engineering © R. Mak Mapping 1:1 Relationships, cont’d 30 Database Systems by Jukić, Vrbsky, & Nestorov Pearson 2014 ISBN Table VEHICLE has the foreign key. Conceptual Logical Physical

Computer Science Dept. Spring 2016: March 10 CS 160 and CMPE/SE 131: Software Engineering © R. Mak 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. 31 Database Systems by Jukić, Vrbsky, & Nestorov Pearson 2014 ISBN

Computer Science Dept. Spring 2016: March 10 CS 160 and CMPE/SE 131: Software Engineering © R. Mak Mapping Example: ER Diagram 32 Database Systems by Jukić, Vrbsky, & Nestorov Pearson 2014 ISBN Conceptual Data Model

Computer Science Dept. Spring 2016: March 10 CS 160 and CMPE/SE 131: Software Engineering © R. Mak Mapping Example: Relational Schema 33 Database Systems by Jukić, Vrbsky, & Nestorov Pearson 2014 ISBN Logical Data Model

Computer Science Dept. Spring 2016: March 10 CS 160 and CMPE/SE 131: Software Engineering © R. Mak Mapping Example: Sample Data 34 Database Systems by Jukić, Vrbsky, & Nestorov Pearson 2014 ISBN Physical Data Model

Computer Science Dept. Spring 2016: March 10 CS 160 and CMPE/SE 131: Software Engineering © R. Mak 35 School Database Example  Initial version IdNameClass_codeSubjectRoom 7003Rogers, Tom926Java programming Thompson, Art908Data structures Lane, John951Software engineering Lane, John974Operating systems Flynn, Mabel931Compilers222 John Lane teaches two classes. Each table has a primary key (PK) field whose value in each record uniquely identifies that record. IdNameTeacher_id_1Teacher_id_2Teacher_id_3 1001Doe, John Novak, Tim null 1009Klein, Leslienull 1014Jane, Mary7051null 1021Smith, Kim Student Teacher  Student id name which teachers  Teacher id name which classes taught  Class class code subject name class room number PK

Computer Science Dept. Spring 2016: March 10 CS 160 and CMPE/SE 131: Software Engineering © R. Mak 36 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.

Computer Science Dept. Spring 2016: March 10 CS 160 and CMPE/SE 131: Software Engineering © R. Mak 37 First Normal Form (1NF)  Separate multi-valued data elements. Break the name fields into last name and first name fields. IdLastFirstTeacher_id_1Teacher_id_2Teacher_id_3 1001DoeJohn NovakTim null 1009KleinLeslienull 1014JaneMary7051null 1021SmithKim IdLastFirstClass_codeSubjectRoom 7003RogersTom926Java programming ThompsonArt908Data structures LaneJohn951Software engineering LaneJohn974Operating systems FlynnMabel931Compilers222 Student Teacher IdNameTeacher_id_1Teacher_id_2Teacher_id_3 1001Doe, John Novak, Tim null 1009Klein, Leslienull 1014Jane, Mary7051null 1021Smith, Kim IdNameClass_codeSubjectRoom 7003Rogers, Tom926Java programming Thompson, Art908Data structures Lane, John951Software engineering Lane, John974Operating systems Flynn, Mabel931Compilers222

Computer Science Dept. Spring 2016: March 10 CS 160 and CMPE/SE 131: Software Engineering © R. Mak 38 First Normal Form, cont’d  Move repeating data elements to a new table. IdLastFirst 1001DoeJohn 1005NovakTim 1009KleinLeslie 1014JaneMary 1021SmithKim Student_idTeacher_id Linking table IdLastFirstClass_codeSubjectRoom 7003RogersTom926Java programming ThompsonArt908Data structures LaneJohn951Software engineering LaneJohn974Operating systems FlynnMabel931Compilers222 Student Teacher Student_Teacher IdLastFirstTeacher_id_1Teacher_id_2Teacher_id_3 1001DoeJohn NovakTim null 1009KleinLeslienull 1014JaneMary7051null 1021SmithKim

Computer Science Dept. Spring 2016: March 10 CS 160 and CMPE/SE 131: Software Engineering © R. Mak 39 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. IdLastFirstClass_codeSubjectRoom 7003RogersTom926Java programming ThompsonArt908Data structures LaneJohn951Software engineering LaneJohn974Operating systems FlynnMabel931Compilers222 Teacher

Computer Science Dept. Spring 2016: March 10 CS 160 and CMPE/SE 131: Software Engineering © R. Mak 40 Second Normal Form (2NF)  Keep related data together (cohesiveness). IdLastFirst 7003RogersTom 7008ThompsonArt 7012LaneJohn 7051FlynnMabel Class_codeTeacher_idSubjectRoom Data structures Java programming Compilers Software engineering Operating systems109 TeacherClass Primary key (PK) Foreign key (FK)  How would you do this relation with a linking table?

Computer Science Dept. Spring 2016: March 10 CS 160 and CMPE/SE 131: Software Engineering © R. Mak 41 Final Database Structure, cont’d IdLastFirst 1001DoeJohn 1005NovakTim 1009KleinLeslie 1014JaneMary 1021SmithKim CodeTeacher_idSubjectRoom Data structures Java programming Compilers Software engineering Operating systems109 Student_idClass_code IdLastFirst 7003RogersTom 7008ThompsonArt 7012LaneJohn 7051FlynnMabel Teacher Student Class Student_Class  John Doe takes Java programming, software engineering, and data structures.

Computer Science Dept. Spring 2016: March 10 CS 160 and CMPE/SE 131: Software Engineering © R. Mak 42 Final Database Structure, cont’d IdLastFirst 1001DoeJohn 1005NovakTim 1009KleinLeslie 1014JaneMary 1021SmithKim CodeTeacher_idSubjectRoom Data structures Java programming Compilers Software engineering Operating systems109 Student_idClass_code IdLastFirst 7003RogersTom 7008ThompsonArt 7012LaneJohn 7051FlynnMabel Teacher Student Class Student_Class  The Java Programming class has John Doe and Kim Smith.

Computer Science Dept. Spring 2016: March 10 CS 160 and CMPE/SE 131: Software Engineering © R. Mak 43 Final Database Structure, cont’d IdLastFirst 1001DoeJohn 1005NovakTim 1009KleinLeslie 1014JaneMary 1021SmithKim CodeTeacher_idSubjectRoom Data structures Java programming Compilers Software engineering Operating systems109 Student_idClass_code IdLastFirst 7003RogersTom 7008ThompsonArt 7012LaneJohn 7051FlynnMabel Teacher Student Class Student_Class  Mabel Flynn teaches compilers.

Computer Science Dept. Spring 2016: March 10 CS 160 and CMPE/SE 131: Software Engineering © R. Mak 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 44