Step 2: Map ER Model to Tables

Similar documents
ER Model. Objectives (2/2) Electricite Du Laos (EDL) Dr. Kanda Runapongsa Saikaew, Computer Engineering, KKU 1

Step 1: Create and Check ER Model

Database Normalization

Step 4: Choose file organizations and indexes

Chapter 17. Methodology Logical Database Design for the Relational Model

Objectives Definition iti of terms List five properties of relations State two properties of candidate keys Define first, second, and third normal for

Fundamentals, Design, and Implementation, 9/e Copyright 2004 Database Processing: Fundamentals, Design, and Implementation, 9/e by David M.

Well-formed XML Documents

Database Management System 6 ER Modeling...

OBJECTIVES. How to derive a set of relations from a conceptual data model. How to validate these relations using the technique of normalization.

The DBMS accepts requests for data from the application program and instructs the operating system to transfer the appropriate data.

Introduction to Java

Programming in the Small II: Control

Distributed Database Systems By Syed Bakhtawar Shah Abid Lecturer in Computer Science

Introduction to Database Design. Dr. Kanda Runapongsa Dept of Computer Engineering Khon Kaen University

4. Entity Relationship Model

XPath. Asst. Prof. Dr. Kanda Runapongsa Saikaew Dept. of Computer Engineering Khon Kaen University

Chapter 12. Entity-Relationship Modeling

David M. Kroenke and David J. Auer Database Processing Fundamentals, Design, and Implementation

ER to Relational Mapping

Objectives of logical design... Transforming the ERD diagram into relations. Relational database components. Mapping a composite attribute

High-Level Database Models (ii)

Advanced Computer Programming

Modern Systems Analysis and Design

Logical Database Design. ICT285 Databases: Topic 06

Relational Database Components

XML Parsers. Asst. Prof. Dr. Kanda Runapongsa Saikaew Dept. of Computer Engineering Khon Kaen University

Database Systems: Design, Implementation, and Management Tenth Edition. Chapter 4 Entity Relationship (ER) Modeling

Translation of ER-diagram into Relational Schema. Dr. Sunnie S. Chung CIS430/530

Correctness and Robustness

Detailed Data Modelling. Detailed Data Modelling. Detailed Data Modelling. Identifying Attributes. Attributes

Database Principles: Fundamentals of Design, Implementation, and Management Tenth Edition. Chapter 7 Data Modeling with Entity Relationship Diagrams

Chapter 2 Entity-Relationship Data Modeling: Tools and Techniques. Fundamentals, Design, and Implementation, 9/e

ER Modeling ER Diagram ID-Dependent and Weak Entities Pg 1

Chapter 6. Advanced Data Modeling. Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel

COMP102: Introduction to Databases, 9.1

Entity-Relationship Models: Good Design and Constraints

Entity Relationship Diagram (ERD): Basics

Chapter 4. The Relational Model

8) A top-to-bottom relationship among the items in a database is established by a

2004 John Mylopoulos. The Entity-Relationship Model John Mylopoulos. The Entity-Relationship Model John Mylopoulos

CMP-3440 Database Systems

Detailed Data Modelling: Attribute Collection and Normalisation of Data

Database Principles: Fundamentals of Design, Implementation, and Management Tenth Edition. Chapter 8 Data Modeling Advanced Concepts

Data about data is database Select correct option: True False Partially True None of the Above

Full file at Chapter 2: Foundation Concepts

LELCTURE 4: ENHANCED ENTITY-RELATIONSHIP MODELING (EER)

Lecture2: Database Environment

Relational model continued. Understanding how to use the relational model. Summary of board example: with Copies as weak entity

ER-to-Relational Mapping

User Interface: Layout. Asst. Prof. Dr. Kanda Runapongsa Saikaew Computer Engineering Khon Kaen University

High Level Database Models

Systems Analysis and Design Methods Chapter 7: Data Modeling and Analysis

CMP-3440 Database Systems

Course on Database Design Carlo Batini University of Milano Bicocca Part 5 Logical Design

XV. The Entity-Relationship Model

CSE 880:Database Systems. ER Model and Relation Schemas

Techno India Batanagar Computer Science and Engineering. Model Questions. Subject Name: Database Management System Subject Code: CS 601

Chapter 2 Entity-Relationship Data Modeling: Tools and Techniques. Fundamentals, Design, and Implementation, 9/e

CS403- Database Management Systems Solved Objective Midterm Papers For Preparation of Midterm Exam

DATA MODELING USING THE ENTITY-RELATIONSHIP MODEL. 1 Powered by POeT Solvers Limited

System Analysis & design

The Entity-Relationship Model (ER Model) - Part 2

Database Systems: Design, Implementation, and Management Tenth Edition. Chapter 4 Entity Relationship (ER) Modeling

Database Management

CS403- Database Management Systems Solved MCQS From Midterm Papers. CS403- Database Management Systems MIDTERM EXAMINATION - Spring 2010

Introduction to Databases

Entity Relationship Modeling. From Rob and Coronel (2004), Database Systems: Design, Implementation, and Management

In This Lecture. The Relational Model. The Relational Model. Relational Data Structure. Unnamed and named tuples. New thing:scheme (and attributes)

Chapter 1 SQL and Data

Lecture3: Data Modeling Using the Entity-Relationship Model.

Translating an ER Diagram to a Relational Schema

Modern Systems Analysis and Design Seventh Edition

Objectives Definition iti of terms Importance of data modeling Write good names and definitions for entities, relationships, and attributes Distinguis

Represent entities and relations with diagrams

CS Reading Packet: "Database design, part 1"

Advanced Computer Programming

RELATIONAL DATA MODEL

The Entity/Relationship (E/R) Model & DB Design. csc343, Introduction to Databases Renée J. Miller and Fatemeh Nargesian and Sina Meraji Winter 2018

Chapter 9: Relational DB Design byer/eer to Relational Mapping Relational Database Design Using ER-to- Relational Mapping Mapping EER Model

Entity Relationship Modelling

CTL.SC4x Technology and Systems

MIT Database Management Systems Lesson 03: ER-to-Relational Mapping

Data Analysis 1. Chapter 2.1 V3.1. Napier University Dr Gordon Russell

Chapter 4. In this chapter, you will learn:

Introduction to Relational Databases. Introduction to Relational Databases cont: Introduction to Relational Databases cont: Relational Data structure

Entity Relationship Diagram (ERD) Dr. Moustafa Elazhary

Conceptual Database Design

Chapter 2: Entity-Relationship Model. Entity Sets. Entity Sets customer and loan. Attributes. Relationship Sets. A database can be modeled as:

Unified Modeling Language (UML)

Review -Chapter 4. Review -Chapter 5

Relational Model (cont d) & Entity Relational Model. Lecture 2

Chapter A: Network Model

Topic 5: Mapping of EER Diagrams to Relations

MIDTERM EXAMINATION Spring 2010 CS403- Database Management Systems (Session - 4) Ref No: Time: 60 min Marks: 38

Basic Concepts. Chapter A: Network Model. Cont.) Data-Structure Diagrams (Cont( Data-Structure Diagrams. Basic Concepts

Entity-Relationship Model. From Chapter 5, Kroenke book

- Database: Shared collection of logically related data and a description of it, designed to meet the information needs of an organization.

1D D0-541 CIW v5 Database Design Specialist Version 1.7

Advanced Computer Programming

Transcription:

Step 2: Map ER Model to Tables Asst. Prof. Dr. Kanda Runapongsa Saikaew (krunapon@kku.ac.th) Dept of Computer Engineering Khon Kaen University Overview How to map a set of tables from an ER model How to check that the tables are well structured using normalization How to check that the tables are capable of supporting the transactions required by the user How to define and document integrity constraints on the tables. 2 Step 2 Map ER model to tables How to define and document integrity constraints on the tables Step 2.1 Create tables Step 2.2 Check table structures using normalization Step 2.3 Check tables support user transactions Step 2.4 Check business rules Step 2.5 Review logical database design with users 3 Dr. Kanda Runapongsa Saikaew, Computer Engineering, KKU 1

Step 2.1 Create tables Create tables for the ER model to represent the entities, relationships, attributes, and constraints. Tables created from information that describes the ER model, including the ER diagrams, data dictionary, and any other supporting documentation 4 Step 2.1 Map tables Discuss using example ER 5 How to represent entities For each entity in ER model, create a table that includes all the entity s simple attributes For composite attributes, include only the simple attributes Where possible, identify the column(s) that make up the primary key in each table 6 Dr. Kanda Runapongsa Saikaew, Computer Engineering, KKU 2

Initial table structures for the entities 7 How to represent relationships (1/2) Use primary key/foreign key mechanism In deciding where to post (or place) the foreign key attribute(s), must first identify the parent and child entities involved in the relationship. The parent entity refers to the entity that posts a copy of its primary key into the table that represents the child entity, to act as the foreign key 8 How to represent relationships (2/2) Consider how to represent the following relationships: one-to-many (1:*) binary relationships; one-to-many (1:*) recursive relationships; one-to-one (1:1) binary relationships; one-to-one (1:1) recursive relationships; many-to-many (*:*) binary relationships; complex relationships; Also, consider multi-valued attributes 9 Dr. Kanda Runapongsa Saikaew, Computer Engineering, KKU 3

1:* binary relationships Entity on one side of relationship is designated as the parent entity and entity on many side is designated as child entity. A copy of primary key of parent entity is placed into table representing the child entity, to act as a foreign key 10 1:* relationship (a) ER diagram; (b) as tables 11 1:* recursive relationships The representation of a 1:* recursive relationship is similar to 1:* binary relationship However, in this case, both the parent and child entity is the same entity 12 Dr. Kanda Runapongsa Saikaew, Computer Engineering, KKU 4

1:* recursive relationships (a) ER diagram; (b) as tables 13 1:1 binary relationships Cannot use cardinality to help identify the parent and child entities. Instead, use participation to help decide whether it s best to represent the relationship By combining the entities involved into one table By creating two tables and posting a copy of the primary key from one table to the other 14 1:1 relationships participation constraints Consider how to create tables to represent the following participation constraints: Mandatory participation on both sides of 1:1 relationship Mandatory participation on one side of 1:1 relationship Optional participation on both sides of 1:1 relationship. 15 Dr. Kanda Runapongsa Saikaew, Computer Engineering, KKU 5

Mandatory participation on both sides of 1:1 relationship Combine entities involved into one table Choose one of the primary keys of the original entities to be the primary key of the new table Choose the other key as an alternate key 16 Mandatory participation on both sides of 1:1 relationship (a) ER diagram; (b) as table Pearson Education Limited, 2004 17 Mandatory participation on one side of a 1:1 relationship Identify parent and child entities using participation constraints. Entity with optional participation is parent entity, and entity with mandatory participation is child entity. A copy of primary key of parent entity is placed in the table representing the child entity. 18 Dr. Kanda Runapongsa Saikaew, Computer Engineering, KKU 6

Mandatory participation on one side of a 1:1 relationship (a)er diagram; (b) as tables 19 Mandatory participation on one side of a 1:1 relationship (2 nd Example) Pearson Education Limited, 2004 20 Optional participation on both sides of a 1:1 relationship In this case, the designation of the parent and child entities is arbitrary You can find out more about the relationship that can help you reach a decision one way or the other 21 Dr. Kanda Runapongsa Saikaew, Computer Engineering, KKU 7

Optional participation on both sides of a 1:1 relationship (a) ER diagram; (b) as tables Pearson Education Limited, 2004 22 1:1 recursive relationships Follow rules for participation as described for a 1:1 relationship. However, in this case, the entity on both sides of the relationship is the same 23 1:1 recursive relationships with mandatory participation on both sides Represent as a single table with two copies of the primary key. One copy of the primary key represents a foreign key and should be renamed to indicate the relationship it represents. 24 Dr. Kanda Runapongsa Saikaew, Computer Engineering, KKU 8

1:1 recursive relationships with mandatory participation on one side There are two ways 1) Can create a single table with two copies of the primary key 2) Create a new table to represent the relationship. New table has two columns, both copies of the primary key acting as foreign keys Must be renamed to indicate purpose of each in the table. 25 1:1 recursive relationships with optional participation on both sides Create a new table to represent the relationship. New table has two columns, both copies of the primary key acting as foreign keys Must be renamed to indicate purpose of each in the table 26 *:* binary relationships Create a table to represent the relationship and include any attributes that are part of the relationship. Post a copy of the primary key attribute(s) of the entities that participate in the relationship into the new table, to act as foreign keys. One or both of the foreign keys will also form the primary key of the new table, possibly in combination with some of the attributes of the relationship. 27 Dr. Kanda Runapongsa Saikaew, Computer Engineering, KKU 9

*:* binary relationships (a) ER diargram; (b) as tables Pearson Education Limited, 2004 28 Complex relationships Create a table to represent the relationship. Post a copy of the primary key attribute(s) of the entities that participate in the complex relationship into the new table, to act as foreign keys Include any attributes that are associated with the relationship One or more of the foreign keys will also form the primary key of the new table 29 Complex relationship ER diagram 30 Dr. Kanda Runapongsa Saikaew, Computer Engineering, KKU 10

Complex relationship representation as tables 31 Multi-valued attributes A new table is created to hold the multi-valued attribute and the parent entity posts a copy of its primary key, to act as a foreign key If the multi-valued attribute is an alternate key of the parent entity The primary key of the new table is composed of the multi-valued attribute and the original primary key of the parent entity 32 Multi-valued attributes ER diagram and representation as tables 33 Dr. Kanda Runapongsa Saikaew, Computer Engineering, KKU 11

How to represent entities, relationships and multi-valued attributes as tables Pearson Education Limited, 2004 34 Tables for the Branch user views of StayHome 35 Step 2.2 Check table structures using normalization Check composition of each table using the rules of normalization, to avoid unnecessary duplication of data Ensure each table is in at least 3NF 36 Dr. Kanda Runapongsa Saikaew, Computer Engineering, KKU 12

Step 2.2 Check table structures using normalization If tables are not in 3NF, this may indicate that part of the ER model is incorrect, or that error(s) introduced while creating the tables from the model If necessary, may need to restructure the data model and/or tables 37 Step 2.3 Check tables support user transactions Check tables support the required transactions, which were documented in the users requirements specification. Ensures that no error has been introduced while creating tables. 38 Step 2.3 Check tables support user transactions One approach is to examine transaction s data requirements to ensure that the data is present in one or more tables If a transaction requires data in more than one table, check these tables are linked through the primary key/foreign key mechanism 39 Dr. Kanda Runapongsa Saikaew, Computer Engineering, KKU 13

Step 2.3 Check tables support user transactions (1/3) 40 Step 2.3 Check tables support user transactions (2/3) 41 Step 2.3 Check tables support user transactions (3/3) 42 Dr. Kanda Runapongsa Saikaew, Computer Engineering, KKU 14

Step 2.4 Check business rules Business rules are the constraints that you wish to impose in order to protect the database from becoming incomplete, inaccurate, or inconsistent 43 Step 2.4 Check business rules Consider the following types of business rules: required data, column domain constraints, entity integrity, multiplicity, referential integrity, other business rules. 44 Step 2.4 Check business rules - referential integrity There are two issues regarding foreign keys Are nulls allowed for the foreign key? How do you ensure referential integrity? Must specify existence constraints, which define conditions under which a primary key or foreign key may be inserted, updated, or deleted. 45 Dr. Kanda Runapongsa Saikaew, Computer Engineering, KKU 15

How do you ensure referential integrity? Consider the following six cases. Case 1: Insert record into child table Case 2: Delete record from child table Case 3: Update foreign key of child record Case 4: Insert record into parent table Case 5: Delete record from parent table Case 6: Update primary key of parent record There are several strategies to consider for Case 5 Pearson Education Limited, 2004 46 Case 5: Delete record from parent table Strategies to consider include: NO ACTION CASCADE SET NULL SET DEFAULT NO CHECK Pearson Education Limited, 2004 47 Referential integrity constraints for the tables Pearson Education Limited, 2004 48 Dr. Kanda Runapongsa Saikaew, Computer Engineering, KKU 16

Step 2.5 Review logical database design with users To ensure that the logical database design is a true representation of the data requirements of an organization (or part of the organization) to be supported by the database Review the database design with users Pearson Education Limited, 2004 49 Summary Step 2: Map ER model to tables Step 2.1 Create tables Step 2.2 Check table structures using normalization Step 2.3 Check tables support user transactions Step 2.4 Check business rules Step 2.5 Review logical database design with users 50 References Connolly and Begg, Database Systems: A Practical Approach to Design, Implementation and Management, Pearson, 2004 51 Dr. Kanda Runapongsa Saikaew, Computer Engineering, KKU 17