© Jalal Kawash 2010 Databases & Data Modelling Peeking into Computer Science.

Slides:



Advertisements
Similar presentations
Convert ER to Relational Database Entity relation Entity relation Attributes attributes Attributes attributes Primary key primary key Primary key primary.
Advertisements

BUSINESS DRIVEN TECHNOLOGY Plug-In T4 Designing Database Applications.
Ch 10, Functional Dependencies and Normal forms
Copyright © 2015 Pearson Education, Inc. Database Design Chapters 17 and
Mapping an ERD to a Relational Database To map an ERD to a relational database, five rules are defined to govern how tables are constructed. 1)Rule for.
James Tam Databases In this section of notes you will learn about: different types of databases, how information is stored in databases, the different.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide
Entity-Relationship Model and Diagrams (continued)
1 © Prentice Hall, 2002 Chapter 5: Logical Database Design and the Relational Model Modern Database Management 6 th Edition Jeffrey A. Hoffer, Mary B.
1 Functional Dependency and Normalization Informal design guidelines for relation schemas. Functional dependencies. Normal forms. Normalization.
Modern Systems Analysis and Design Third Edition
Database Design Concepts INFO1408 Term 2 week 1 Data validation and Referential integrity.
©Silberschatz, Korth and Sudarshan2.1Database System Concepts Reduction of an E-R Schema to Tables A database which conforms to an E-R diagram can be represented.
Slide 1 Chapter 05 – Part 1 Data Modeling with the Entity-Relationship Model.
CSCI 242 Relational Data Modeling Copyright 2011, David C. Roberts, all rights reserved.
APPENDIX C DESIGNING DATABASES
Michael F. Price College of Business Chapter 6: Logical database design and the relational model.
Lecture4: Informal guidelines for good relational design Mapping ERD to Relation Ref. Chapter3 Lecture4 1.
© Jalal Kawash Databases & Data Modeling Peeking into Computer Science.
Database Design Concepts
DATA MODELING AND DATABASE DESIGN
MIS 385/MBA 664 Systems Implementation with DBMS/ Database Management Dave Salisbury ( )
Chapter 9 Designing Databases Modern Systems Analysis and Design Sixth Edition Jeffrey A. Hoffer Joey F. George Joseph S. Valacich.
Data Modelling – ERD Entity Relationship Diagram’s Entity Relationship Diagrams and how to create them. 1.
Concepts and Terminology Introduction to Database.
Chapter 3: Relational Model I Structure of Relational Databases Structure of Relational Databases Convert a ER Design to a Relational Database Convert.
Database Management COP4540, SCS, FIU Relational Model Chapter 7.
© Jalal Kawash Databases & Data Modelling Peeking into Computer Science.
Logical Database Design Relational Model. Logical Database Design Logical database design: process of transforming conceptual data model into a logical.
Chapter 3: Relational Model  Structure of Relational Databases  Normal forms (chap. 7)  Reduction of an E-R Schema to Relational (Sect. 2.9)  Relational.
Functional Dependencies and Normalization for Relational Databases.
© Jalal Kawash 2010 Trees & Information Coding Peeking into Computer Science.
M1G Introduction to Database Development 2. Creating a Database.
1 Entity-Relationship Diagram. 2 Components of ERD: –Entity –Relationship –Cardinality –Attributes.
1 Session 2 Welcome: The seventh learning sequence “ Reduction of an EER schema to tables“ Recap : In the previous learning sequence, we discussed the.
Logical Database Design (1 of 3) John Ortiz Lecture 6Logical Database Design (1)2 Introduction  The logical design is a process of refining DB schema.
Copyright 2006 Prentice-Hall, Inc. Essentials of Systems Analysis and Design Third Edition Joseph S. Valacich Joey F. George Jeffrey A. Hoffer Chapter.
© Jalal Kawash Database Queries Peeking into Computer Science.
COMP1212 COMP1212 Anomalies and Dependencies Dr. Mabruk Ali.
Data modeling using the entity-relationship model Chapter 3 Objectives How entities, tuples, attributes and relationships among entities are represented.
1 Translating ER Schema to Relational Model Instructor: Mohamed Eltabakh
ICOM 5016 – Introduction to Database Systems Lecture 9 Dr. Manuel Rodriguez Department of Electrical and Computer Engineering University of Puerto Rico,
1 Functional Dependencies and Normalization Chapter 15.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan Lecture-03 Introduction –Data Models Lectured by, Jesmin Akhter.
Chapter 9 Logical Database Design : Mapping ER Model To Tables.
Copyright © 2013 by The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill/Irwin APPENDIX C DESIGNING DATABASES APPENDIX C DESIGNING DATABASES.
Chapter 7 Functional Dependencies Copyright © 2004 Pearson Education, Inc.
© Jalal Kawash Database Queries Peeking into Computer Science.
Chapter 10 Designing Databases. Objectives:  Define key database design terms.  Explain the role of database design in the IS development process. 
Link tables and keys Access/IPS Walsall College of Arts & Technology.
Lecture4: Informal guidelines for good relational design Mapping ERD to Relation Prepared by L. Nouf Almujally Ref. Chapter3 Lecture4 1.
Copyright © 2009 Pearson Education, Inc. Publishing as Prentice Hall Chapter 9 Designing Databases 9.1.
Understand Relational Database Management Systems Software Development Fundamentals LESSON 6.1.
1 © Prentice Hall, 2002 ITD1312 Database Principles Chapter 4B: Logical Design for Relational Systems -- Transforming ER Diagrams into Relations Modern.
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.
Chapter 2: Entity-Relationship Model. 3.2 Chapter 2: Entity-Relationship Model Design Process Modeling Constraints E-R Diagram Design Issues Weak Entity.
©Silberschatz, Korth and Sudarshan7.1Database System Concepts - 6 th Edition Chapter 7: Entity-Relationship Model.
Lecture 4: Logical Database Design and the Relational Model 1.
Al-Imam University Girls Education Center Collage of Computer Science 1 st Semester, 1432/1433H Chapter 10_part 1 Functional Dependencies and Normalization.
CS3431: C-Term Translating ER Schema to Relational Model Instructor: Mohamed Eltabakh
1 The Relational Data Model David J. Stucki. Relational Model Concepts 2 Fundamental concept: the relation  The Relational Model represents an entire.
Chapter 15 1 Functional Dependencies and Normalization for Relational Databases تنبيه : شرائح العرض (Slides) هي وسيلة لتوضيح الدرس واداة من الادوات في.
Database Designsemester Slide 1 Database Design Lecture 7 Entity-relationship modeling Text , 7.1.
Translating ER Schema to Relational Model
Chapter 4 Logical Database Design and the Relational Model
Chapter 15 Basics of Functional Dependencies and Normalization for Relational Databases.
Session 2 Welcome: The seventh learning sequence
Database Normalisation
Mapping an ERD to a Relational Database
Presentation transcript:

© Jalal Kawash 2010 Databases & Data Modelling Peeking into Computer Science

© Jalal Kawash 2010Peeking into Computer Science Reading Assignment Mandatory: Chapter 4 – Sections 4.4 & 4.5 2

Mapping ERDs to Schema 3

© Jalal Kawash 2010Peeking into Computer Science Objectives At the end of this section, you will be able to: 1. Apply the mapping algorithm to translate an ERD to a database schema 2. Understand foreign keys

© Jalal Kawash 2010Peeking into Computer Science Mapping Algorithm (4.1) 1. Each entity type is translated to a table; its attributes become columns 2. Each many-to-many relationship type becomes a table; the columns are the primary keys of the participating entity types 3. For each one-to-many relationship type, add the primary keys of the entity type on the one side as columns in the table corresponding to the entity type on the many side 5

© Jalal Kawash 2010Peeking into Computer Science Mapping Entity Types 1. Each entity type is translated to a table; its attributes become columns 6

© Jalal Kawash 2009Peeking into Computer Science 7 EMPLOYEE - SIN - First name - Last name - DOB - Gender - Salary - Number - Street - City - Postal Code DEPARTMENT -Number -Name PROJECT - Number - Name - Location

© Jalal Kawash 2009Peeking into Computer Science JT’s Extra: Recall Many : Many Relations Can’t Be Implemented

© Jalal Kawash 2009Peeking into Computer Science JT’s Extra Mapping Many-Many Relationship Types 2. Each many-to-many relationship type becomes a table; the columns are the primary keys of the participating entity types 9

© Jalal Kawash 2010Peeking into Computer Science Participation Levels 10 EMPLOYEE - SIN - First name - Last name - DOB - Gender - Salary - Number - Street - City - Postal Code DEPARTMENT -Number -Name PROJECT - Number - Name - Location CONTROLS WORKS ON WORKS FOR

© Jalal Kawash 2009Peeking into Computer Science There will be no more tables Step 3 simply augments the existing tables

© Jalal Kawash 2009Peeking into Computer Science There will be no more tables Step 3 simply augments the existing tables JT’s Extra: (In case you missed it in Jalal’s example)

© Jalal Kawash 2010Peeking into Computer Science Mapping One-Many Relationship Types 3. For each one-to-many relationship type, add the primary keys of the entity type on the one side as columns in the table corresponding to the entity type on the many side 13

© Jalal Kawash 2010Peeking into Computer Science Mapping One-Many Relationship Types 3. For each one-to-many relationship type, add the primary keys of the entity type on the one side as columns in the table corresponding to the entity type on the many side 14 JT’s Extra Table 1Table 2 1 Many Primary key Foreign key

© Jalal Kawash 2010Peeking into Computer Science JT’s Extra: Foreign Keys A key in one table that refers to a key in another field.

© Jalal Kawash 2009Peeking into Computer Science 16 EMPLOYEE - SIN - First name - Last name - DOB - Gender - Salary - Number - Street - City - Postal Code DEPARTMENT -Number -Name PROJECT - Number - Name - Location CONTROLS WORKS ON WORKS FOR Dnumber tells us which Department an employee works for Dnumber is a foreign Key

© Jalal Kawash 2009Peeking into Computer Science 17 EMPLOYEE - SIN - First name - Last name - DOB - Gender - Salary - Number - Street - City - Postal Code DEPARTMENT -Number -Name PROJECT - Number - Name - Location CONTROLS WORKS ON WORKS FOR JT’s Extra (in case you missed in Jalal’s slide): “Number” (primary key in ‘Department’ table): “one” side “Dnumber” (foreign key in ‘Employee’ table): “many” side

© Jalal Kawash 2009Peeking into Computer Science 18

© Jalal Kawash 2009Peeking into Computer Science 19 EMPLOYEE - SIN - First name - Last name - DOB - Gender - Salary - Number - Street - City - Postal Code DEPARTMENT -Number -Name PROJECT - Number - Name - Location CONTROLS WORKS ON WORKS FOR

© Jalal Kawash 2009Peeking into Computer Science 20

© Jalal Kawash 2009Peeking into Computer Science The Complete Schema

© Jalal Kawash 2010Peeking into Computer Science Two Missing Things The mapping algorithm does not include one-to-one relationship types ◦We need to include these Sometimes, relationship types may need to have their own attributes Will revise ERDs and the mapping algorithm to include these. 22

© Jalal Kawash 2010Peeking into Computer Science MANAGES Relationship Type A department is managed by one employee Each department has a manager which is also an employee EMPLOYEE and DEPARTMENT are related by the MANAGES relationship type Each department can have only one manager, and each employee can manage at most one department. This is a one-to-one relationship 23

© Jalal Kawash 2009Peeking into Computer Science EMPLOYEE - SIN - First name - Last name - DOB - Gender - Salary - Number - Street - City - Postal Code DEPARTMENT -Number -Name PROJECT - Number - Name - Location CONTROLS WORKS ON WORKS FOR MANAGES

© Jalal Kawash 2010Peeking into Computer Science Attributes for Relationship types 25 EMPLOYEE - SIN - First name - Last name - DOB - Gender - Salary - Number - Street - City - Postal Code DEPARTMENT -Number -Name PROJECT - Number - Name - Location CONTROLS WORKS ON WORKS FOR MANAGES - Hours - Start date

© Jalal Kawash 2010Peeking into Computer Science JT’s Extra: Notation Reminder Entity (object in real world): E Table (in database): T Relationship: R Entity: E

© Jalal Kawash 2010Peeking into Computer Science Complete mapping Algorithm 1. Each entity type E is translated to a table T (to emphasize that T is a result of E, we write T(E)) ◦ T’s columns are E’s attributes 2. Each many-to-many relationship type R, relating entity types E1 and E2, becomes a table T ◦T’s columns are R’s attributes ◦ the primary key of E1 and E2 is added as columns in T 27

© Jalal Kawash 2010Peeking into Computer Science Complete mapping Algorithm 3. For each one-to-many relationship type R, relating E1 to E2 with E1 on the “one” side: ◦add the primary key of E1 as columns in T(E2) ◦any attributes that R has become columns in T(E2) 28

© Jalal Kawash 2010Peeking into Computer Science Complete mapping Algorithm 4. For each one-to-one relationship type R, relating E1 to E2 with E1 on a partial participation side or both E1 and E2 fully participate in R: ◦add the primary key of E1 as columns in T(E2) ◦any attributes that R has become columns in T(E2) 29

© Jalal Kawash 2010Peeking into Computer Science JT’s Extra: 1 to 1 Relationships To ensure compliance with good design principles, examine participation levels when determining which table’s primary key is used as the other table’s foreign key. ◦If both tables participate equally (both partial or both full) then the choice is arbitrary. T1T2T1T2 OR

© Jalal Kawash 2010Peeking into Computer Science ◦If participation levels aren’t equal: If one table partially participates in the relationship while the other table participates partially in the relationship. JT’s Extra: 1 to 1 Relationships (2) Table 2Table 1 Primary key Foreign key Full Partial

© Jalal Kawash 2010Peeking into Computer Science JT’s Extra: Attributes Of Relationships Employee Project Works on Many Hours? Hours!

© Jalal Kawash 2010Peeking into Computer Science JT’s Extra: Attributes Of Relationships (2) Employee Department Manages One Many Works for One Many Start date? One Start date!

© Jalal Kawash 2009Peeking into Computer Science 34 EMPLOYEE - SIN - First name - Last name - DOB - Gender - Salary - Number - Street - City - Postal Code DEPARTMENT -Number -Name PROJECT - Number - Name - Location CONTROLS WORKS ON WORKS FOR MANAGES - Hours - Start date

© Jalal Kawash 2009Peeking into Computer Science 35 EMPLOYEE - SIN - First name - Last name - DOB - Gender - Salary - Number - Street - City - Postal Code DEPARTMENT -Number -Name PROJECT - Number - Name - Location CONTROLS WORKS ON WORKS FOR MANAGES - Hours - Start date

© Jalal Kawash 2009Peeking into Computer Science The Complete Schema

Design Principles What makes a Good Design? 37

© Jalal Kawash 2010Peeking into Computer Science Objectives At the end of this section, you will be able to: 1. List and entertain the three basic design principles 2. Understand how our mapping algorithm satisfies these three principles

© Jalal Kawash 2010Peeking into Computer Science Basic Design Principles 1. Meaning of a Schema should be easily explained 2. Reduce Redundancy 3. Reduce NULL values 39

© Jalal Kawash 2010Peeking into Computer Science Design Principle (1) 1. Design a schema so that its meaning can be easily explained Do NOT combine attributes from different entity types into a single table 40

© Jalal Kawash 2010Peeking into Computer Science A schema with no clear meaning Project, department, or controls table?

© Jalal Kawash 2010Peeking into Computer Science Design Principle (2) 2. Design a schema so that Redundancy is reduced Unnecessary Redundancy can lead to modification anomalies 42

© Jalal Kawash 2010Peeking into Computer Science Unnecessary Redundancy Assume the schema definition for Project and Department ◦migrating Pnumber to DEPARTMENT 43

© Jalal Kawash 2009Peeking into Computer Science 44 4 More than one place to change IT

© Jalal Kawash 2010Peeking into Computer Science Modification Anomaly Example ABC company decides to change the name of IT department to Technology 45

© Jalal Kawash 2010Peeking into Computer Science No Anomalies Here 46 The only place to change IT

© Jalal Kawash 2009Peeking into Computer Science 47 Must change all occurrences of IT here and elsewhere IT occurs in more than one place

© Jalal Kawash 2009Peeking into Computer Science JT’s Extra: Null Values Refers to empty fields of a record. Primary keys cannot be null but other fields may be null.

© Jalal Kawash 2010Peeking into Computer Science Design Principle (3) 3. Design a schema so that NULL values are minimized as much as possible Waste space Result in confusion: ◦A NULL value could mean:  Does not apply  Unknown  To be recorded 49

© Jalal Kawash 2010Peeking into Computer Science NULL Values Confusion NULL 1.Arrangement to work until completion 2.We do not know the hours yet 3.Someone else will enter it (it is known)

© Jalal Kawash 2010Peeking into Computer Science NULL Values Example We migrated the managers SIN (partial participation side) to the DEPARTMENT table (full participation side) 51

© Jalal Kawash 2010Peeking into Computer Science NULL Values Example What if we migrated the department Number to the EMPLOYEE table? 52

© Jalal Kawash 2010Peeking into Computer Science Original Design 53

© Jalal Kawash 2010Peeking into Computer Science Alternative Design 54

© Jalal Kawash 2010Peeking into Computer Science JT’s Extra (Null): Many to many relationships: directly modeled in a database. 55 StudentIDStudentFirstNameStudentLastName JamieSmyth StaceyWalls AngelLam ClassNam e ClassNumberLecture NoClassDescription CPSC20301Introduction to Computers CPSC23101Introduction to Computer Science I CPSC23301Introduction to Computer Science II Students table Classes table

© Jalal Kawash 2010Peeking into Computer Science JT’s Extra (Null): Many to many relationships: directly modeled in a database. 56 StudentIDStudentFirst Name StudentLast Name JamieSmyth StaceyWalls AngelLam Students table Class 1 Class 2 Class 3 Class 4 Class 5 …Class ‘N’ CPSC 203 PSYC 205 MATH 221 MATH 251 SOCI 201 NULL CPSC 203 ART 201 MATH 271 NULL CPSC 203 CHIN 201 KINE 221 MGIS 323 OPMA 341 NULL

© Jalal Kawash 2010Peeking into Computer Science JT’s Extra (Null): Many to many relationships: directly modeled in a database. 57 ClassNa me ClassNu mber Lecture NoClassDescription CPSC20301Introduction to Computers CPSC23101Introduction to Computer Science I CPSC23301Introduction to Computer Science II Classes table S1S1 S2S2 S3S3 S4S4 S5S5 S6S6 S7S7 …SNSN BillBobMaryJaneNULL JimNULL AliceBrettCharli e Deac on ErnieEdgarFredaNULL