Mapping an ERD to a Relational Database



Similar documents
Concepts of Database Management Seventh Edition. Chapter 6 Database Design 2: Design Method

Database Design Process

Lecture 12: Entity Relationship Modelling

Converting E-R Diagrams to Relational Model. Winter Lecture 17

Chapter 7 Data Modeling Using the Entity- Relationship (ER) Model

Database Design Process

Data Modeling. Database Systems: The Complete Book Ch ,

Relational Schema Design

Database Design Overview. Conceptual Design ER Model. Entities and Entity Sets. Entity Set Representation. Keys

Chapter 2: Entity-Relationship Model. Entity Sets. " Example: specific person, company, event, plant

Foundations of Information Management

not necessarily strictly sequential feedback loops exist, i.e. may need to revisit earlier stages during a later stage

Entity Relationship Diagram

A brief overview of developing a conceptual data model as the first step in creating a relational database.

Chapter 3. Data Modeling Using the Entity-Relationship (ER) Model

An Example: Video Rental System

Chapter 2: Entity-Relationship Model

Database Design. Marta Jakubowska-Sobczak IT/ADC based on slides prepared by Paula Figueiredo, IT/DB

Foundations of Information Management

AVOIDANCE OF CYCLICAL REFERENCE OF FOREIGN KEYS IN DATA MODELING USING THE ENTITY-RELATIONSHIP MODEL

Fundamentals of Database Design

THE ENTITY- RELATIONSHIP (ER) MODEL CHAPTER 7 (6/E) CHAPTER 3 (5/E)

Chapter 2: Entity-Relationship Model. E-R R Diagrams

Database Management Systems

CPS352 Database Systems: Design Project

ComponentNo. C_Description UnitOfMeasure. C_Quantity

RELATIONSHIP STRENGTH

COMP 378 Database Systems Notes for Chapter 7 of Database System Concepts Database Design and the Entity-Relationship Model

2. Conceptual Modeling using the Entity-Relationship Model

The Entity-Relationship Model

XV. The Entity-Relationship Model

Lesson 8: Introduction to Databases E-R Data Modeling

We know how to query a database using SQL. A set of tables and their schemas are given Data are properly loaded

Exercise 1: Relational Model

DATABASE MANAGEMENT SYSTEMS. Question Bank:

ER modelling, Weak Entities, Class Hierarchies, Aggregation

Databases and BigData

Relational Database Concepts

Conceptual Design Using the Entity-Relationship (ER) Model

Data Modeling: Part 1. Entity Relationship (ER) Model

Designing a Database Schema

Lecture Notes INFORMATION RESOURCES

Bridge from Entity Relationship modeling to creating SQL databases, tables, & relations

Introduction to normalization. Introduction to normalization

Entity-Relationship Model

Rose Data Modeler (logical)

Design and Implementation

Databases Model the Real World. The Entity- Relationship Model. Conceptual Design. Steps in Database Design. ER Model Basics. ER Model Basics (Contd.

Module 5: Normalization of database tables

7.1 The Information system

Modern Systems Analysis and Design

DATABASE INTRODUCTION

1 Class Diagrams and Entity Relationship Diagrams (ERD)

DATABASE DESIGN. - Developing database and information systems is performed using a development lifecycle, which consists of a series of steps.

Data Modeling Basics

Database Design and the E-R Model

CSC 742 Database Management Systems

Databases What the Specification Says

IT2304: Database Systems 1 (DBS 1)

Database Design. Adrienne Watt. Port Moody

Entity - Relationship Modelling

The Relational Model. Why Study the Relational Model? Relational Database: Definitions. Chapter 3

OVERVIEW 1.1 DATABASE MANAGEMENT SYSTEM (DBMS) DEFINITION:-

Review: Participation Constraints

The Relational Data Model: Structure

Data Analysis 1. SET08104 Database Systems. Napier University

The Entity-Relationship Model

Outline. Data Modeling. Conceptual Design. ER Model Basics: Entities. ER Model Basics: Relationships. Ternary Relationships. Yanlei Diao UMass Amherst

Review Entity-Relationship Diagrams and the Relational Model. Data Models. Review. Why Study the Relational Model? Steps in Database Design

Database Setup. Coding, Understanding, & Executing the SQL Database Creation Script

Data Modelling and E-R Diagrams

Unit 2.1. Data Analysis 1 - V Data Analysis 1. Dr Gordon Russell, Napier University

Toad Data Modeler - Features Matrix

Database IST400/600. Jian Qin. A collection of data? A computer system? Everything you collected for your group project?

The Entity-Relationship Model

Relational Database Basics Review

CSCE 156H/RAIK 184H Assignment 4 - Project Phase III Database Design

IT2305 Database Systems I (Compulsory)

ER & EER to Relational Mapping. Chapter 9 1

How To Write A Diagram

LiTH, Tekniska högskolan vid Linköpings universitet 1(7) IDA, Institutionen för datavetenskap Juha Takkinen

Databasesystemer, forår 2005 IT Universitetet i København. Forelæsning 3: Business rules, constraints & triggers. 3. marts 2005

Lecture 6. SQL, Logical DB Design

Preview DESIGNING DATABASES WITH VISIO PROFESSIONAL: A TUTORIAL

three Entity-Relationship Modeling chapter OVERVIEW CHAPTER

Business Rules Modeling for Business Process Events: An Oracle Prototype

Normalization in OODB Design

Information Systems Modelling Information Systems I: Databases

Designing Databases. Introduction


IV. The (Extended) Entity-Relationship Model

The Relational Model. Ramakrishnan&Gehrke, Chapter 3 CS4320 1

Winter Winter

A Comparative Analysis of Entity-Relationship Diagrams 1

A Tool for Generating Relational Database Schema from EER Diagram

Relational model. Relational model - practice. Relational Database Definitions 9/27/11. Relational model. Relational Database: Terminology

Database Design for the Uninitiated CDS Brownbag Series CDS

Using Entity-Relationship Diagrams To Count Data Functions Ian Brown, CFPS Booz Allen Hamilton 8283 Greensboro Dr. McLean, VA USA

SCHEMAS AND STATE OF THE DATABASE

CIS 631 Database Management Systems Sample Final Exam

Transcription:

Mapping an ERD to a Relational Database We use E/R Modeling to understand the informational needs of a system. Once the model is satisfactory, we then implement our design in a relational database. In order to implement a database we must decide on the relations, their attributes and primary keys. This section contains some simple rules that we use to map an ERD to a relational database. In general, relations are used to hold entity sets and to hold relationship sets. The considerations to be made are listed below. We consider that points 1a), 1b), 2b), and 3a) are likely used more often than the others. After we present the mapping rules, we discuss their application in a few examples. 1. Entity Types Each entity type is implemented with a separate relation. It is important to distinguish entity types as being either strong or weak. a. Strong Entity Types Strong, or regular, entity types are mapped to their own relation. The key attributes are included and the PK is chosen to be one of these keys. b. Weak Entity Types Weak entity types are mapped to their own relation. The PK attributes of any relations created from the related identifying entity types are included as FK attributes. The PK of the relation for the weak entity type is the combination of the PKs of relations (from the related identifying entity types) and the discriminator of the weak entity. 2. Relationships The implementation of relationships involve the use of foreign keys. Recall, as discussed in point 1.b) above, that if the relationship is identifying, then the primary key of the strong entity must be propagated to the relation representing the weak entity. It is important to consider both the degree and the cardinality of a relationship. In the following, the first three cases deal with binary relationships and the fourth concerns n- ary relationships. a. Binary One-To-One In general, with a one-to-one relationship, you have a choice regarding where to implement the relationship. You may choose to place a foreign key in one of the 1

two relations, or in both. Also, include any attributes defined for the relationship in the same table as the foreign key. b. Binary One-To-Many With a one-to-many relationship you must place a foreign key (and any attributes defined for the relationship) in the relation corresponding to the many side of the relationship. c. Binary Many-To-Many A many-to-many relationship must be implemented with a separate relation. This new relation will have a composite primary key comprising the primary keys of the relations implementing the participating entity types plus any discriminator attribute. Also include as attributes, in this relation, any attributes defined for the relationship. d. n-ary, n>2 A new relation is generated for an n-ary relationship type. The attributes in this relation include FKs for each relation (of the related entity types) plus any other attributes defined for the n-ary relationship. This new relation has a composite primary key comprising the n primary keys of the relations of the participating entity types plus any discriminator attribute. There is one exception to the formation of the PK: if the cardinality for any entity type is 1, then the primary key of the relations for that entity type is only included as a foreign key and not as part of the primary key of the new relation. 3. Attributes All attributes, with the exception of derived and composite attributes, must appear in relations. You choose to include derived attributes if their presence will improve performance. If you include a derived attribute in a relation, then you must determine how its values are maintained. In the following we consider attributes according to whether they are atomic(simple), multi-valued, or composite. a. Simple, atomic These are included in the relation created for the pertinent entity set, many-tomany relationship, or n-ary relationship. b. Multi-valued Each multi-valued attribute is implemented using a new relation. This relation will include the primary key of the original entity type and the multi-valued attribute. The primary key of this relation is the primary key of the original entity 2

set and the multi-valued attribute. Note that in this new relation, the attribute is no longer considered as multi-valued. c. Composite Composite attributes are not included. However the simple attributes comprising the composite attribute do appear in the pertinent relation. 4. Participation constraints If a relationship is mandatory for an entity type, and if the entity type is on the many side of the relationship, then a specification for the relation is needed to ensure a foreign key has a value, and that it cannot be null. This specification would be a "NOT NULL" attribute constraint in the DDL of an SQL system, or a "yes" for an attribute's "required" property in an MS Access relation. If a relationship is mandatory for an entity type, and if the entity type is on the one side of a relationship, then a check constraint, database trigger, or application code would be used to enforce the constraint. 3

Example 1: Mapping an ERD to a Relational Database Consider the ERD: Each entity is strong and all attributes are simple, so we have an Employee relation and a Department relation. Because of the 1-to-many relationship we must have a foreign key on the many side of the works in relationship. So, the Employee relation has a foreign key DeptNum. Our relations are: Employee EmpNum EmpFname EmpLname DeptNum The FK DeptNum needs a constraint to ensure it is never null Department DeptNum DeptName. 4

Example 2: Mapping an ERD to a Relational Database Consider the following (star schema) design where there is one "fact" entity type and three "dimension" entity types. The terms fact and dimension are used in "dimensional" modeling. This diagram has three identifying 1-to-many relationships. By applying our mapping rules, we have four relations: three for the dimension entity types (Product, Store, Date) and one for the fact entity type (Sale). The fact relation will have three foreign keys referencing the dimension relations. The primary key of the fact relation comprises those same foreign keys. 5

Our relations are: Store Ssk StLocn Product Psk ProdTitle Date Dsk Day Week Month Quarter Year Sale Ssk Psk Dsk Price Qty. 6

Example 3: Mapping an ERD to a Relational Database This example is similar to the previous one, but we instead of a fact entity set we have a 3-ary (ternary) relationship (a many-to-many-to-many relationship). Now, applying our mapping rules we end up with the same physical database as the previous example.. 7