HNDIT 1105 Database Management Systems

Similar documents
ER & EER to Relational Mapping. Chapter 9 1

Relational Schema. CS 4700/6700 A Sample of Small Database Design Using Microsoft Access

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

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

CSC 443 Data Base Management Systems. Basic SQL

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

Lab Assignment Creating a Relational Database Schema from ER Diagram, Populating the Database and Querying over the database with SQL

Entity-Relationship Model

10CS54: DATABASE MANAGEMENT SYSTEM

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

{ PreviousEducation ( CollegeName, StartDate, EndDate, { Degree (DegreeName, Month, Year) }, { Transcript (CourseName, Semester, Year, Grade) } ) }

Relational Schema Design

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

Databases and BigData

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

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

Normalization in OODB Design

Fundamentals of Database System

Database Systems. Session 3 Main Theme. Enterprise Data Modeling Using The Entity/Relationship (ER) Model. Dr. Jean-Claude Franchitti

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

A Tool for Generating Relational Database Schema from EER Diagram

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

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

Theory of Relational Database Design and Normalization

Lesson 8: Introduction to Databases E-R Data Modeling

Figure 14.1 Simplified version of the

Functional Dependency and Normalization for Relational Databases

Theory of Relational Database Design and Normalization

Review: Participation Constraints

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

Chapter 2: Entity-Relationship Model

The Entity-Relationship Model

Data Analysis 1. SET08104 Database Systems. Napier University

Foundations of Information Management

Conceptual Design Using the Entity-Relationship (ER) Model

Part A: Data Definition Language (DDL) Schema and Catalog CREAT TABLE. Referential Triggered Actions. CSC 742 Database Management Systems

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

The Entity-Relationship Model

Chapter 10 Functional Dependencies and Normalization for Relational Databases

CHAPTER 8: SQL-99: SCHEMA DEFINITION, BASIC CONSTRAINTS, AND QUERIES

Advanced Database Models

Chapter 10. Functional Dependencies and Normalization for Relational Databases. Copyright 2007 Ramez Elmasri and Shamkant B.

SQL-99: Schema Definition, Basic Constraints, and Queries

COSC344 Database Theory and Applications. Lecture 9 Normalisation. COSC344 Lecture 9 1

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

Lab Manual. Database Systems COT-313 & Database Management Systems Lab IT-216

Part 4: Database Language - SQL

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

IT2304: Database Systems 1 (DBS 1)

The Entity-Relationship Model

Data Modeling. Database Systems: The Complete Book Ch ,

IT2305 Database Systems I (Compulsory)

CSC 742 Database Management Systems

SQL Nested & Complex Queries. CS 377: Database Systems

Lecture 12: Entity Relationship Modelling

XV. The Entity-Relationship Model

Chapter 10 Practical Database Design Methodology and Use of UML Diagrams

Chapter 10. Functional Dependencies and Normalization for Relational Databases

Database Design Process

New York University Computer Science Department Courant Institute of Mathematical Sciences

Fundamentals of Database Systems. Laboratory Manual 1. Rajshekhar Sunderraman. Georgia State University. August 2010

Database Design Methodologies

The Relational Algebra

Comp 3311 Database Management Systems. 2. Relational Model Exercises

Entity Relationship Diagram

Database Design Process

Introduction to Database Systems CS4320/CS5320. CS4320/4321: Introduction to Database Systems. CS4320/4321: Introduction to Database Systems

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

Database Design Process. Databases - Entity-Relationship Modelling. Requirements Analysis. Database Design

Fundamentals of Database Design

Relational Normalization: Contents. Relational Database Design: Rationale. Relational Database Design. Motivation

Databases -Normalization III. (N Spadaccini 2010 and W Liu 2012) Databases - Normalization III 1 / 31

Chapter 8. SQL-99: SchemaDefinition, Constraints, and Queries and Views

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

Foundations of Information Management

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

More SQL: Assertions, Views, and Programming Techniques

Lecture 6. SQL, Logical DB Design

How To Use The Database In Jdbc.Com On A Microsoft Gdbdns.Com (Amd64) On A Pcode (Amd32) On An Ubuntu (Amd66) On Microsoft

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

Database Design Methodology

ER modelling, Weak Entities, Class Hierarchies, Aggregation

2. Conceptual Modeling using the Entity-Relationship Model

Database Design Methodology

Databases What the Specification Says

Objectives of Lecture 1. Class and Office Hours. Labs and TAs. CMPUT 391: Introduction. Introduction

Boyce-Codd Normal Form

Grocery Store Project

Relational Database Design Theory

B.Sc. (Computer Science) First Year

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

featuring data privacy Andres Avelino Campos Sainz A Project submitted in partial fulfillment of the requirements for the degree of

TYPICAL QUESTIONS & ANSWERS

Rose Data Modeler (logical)

Database Design. Database Design I: The Entity-Relationship Model. Entity Type (con t) Chapter 4. Entity: an object that is involved in the enterprise

Chapter 10. Practical Database Design Methodology. The Role of Information Systems in Organizations. Practical Database Design Methodology

Transcription:

HNDIT 1105 Database Management Systems Lesson 03: Relational Database Design by ER-to- Relational Mapping By S. Sabraz Nawaz M.Sc. In IS (SLIIT), PGD in IS (SLIIT), BBA (Hons.) Spl. in IS (SEUSL), MIEEE, MAIS Senior Lecturer in MIT Department of Management and IT, SEUSL

Chapter Outline ER-to-Relational Mapping Algorithm o Step 1: Mapping of Regular Entity Types o Step 2: Mapping of Weak Entity Types o Step 3: Mapping of Binary 1:1 Relation Types o Step 4: Mapping of Binary 1:N Relationship Types. o Step 5: Mapping of Binary M:N Relationship Types. o Step 6: Mapping of Multivalued attributes. o Step 7: Mapping of N-ary Relationship Types. HNDIT 1105, DBMS By: S.Sabraz Nawaz 2

ER-to-Relational Mapping Algorithm Step 1: Mapping of Regular Entity Types. o For each regular (strong) entity type E in the ER schema, create a relation R that includes all the simple attributes of E. o Choose one of the key attributes of E as the primary key for R. o If the chosen key of E is composite, the set of simple attributes that form it will together form the primary key of R. Example: We create the relations EMPLOYEE, DEPARTMENT, and PROJECT in the relational schema corresponding to the regular entities in the ER diagram. o SSN, DNUMBER, and PNUMBER are the primary keys for the relations EMPLOYEE, DEPARTMENT, and PROJECT as shown. HNDIT 1105, DBMS By: S.Sabraz Nawaz 3

The ER conceptual schema diagram for the COMPANY database HNDIT 1105, DBMS By: S.Sabraz Nawaz Slide 9-4

Step 1: Mapping of Regular Entity Types

ER-to-Relational Mapping Algorithm (contd.) Step 2: Mapping of Weak Entity Types o For each weak entity type W in the ER schema with owner entity type E, create a relation R & include all simple attributes (or simple components of composite attributes) of W as attributes of R. o Also, include as foreign key attributes of R the primary key attribute(s) of the relation(s) that correspond to the owner entity type(s). o The primary key of R is the combination of the primary key(s) of the owner(s) and the partial key of the weak entity type W, if any. Example: Create the relation DEPENDENT in this step to correspond to the weak entity type DEPENDENT. o Include the primary key SSN of the EMPLOYEE relation as a foreign key attribute of DEPENDENT (renamed to ESSN). o The primary key of the DEPENDENT relation is the combination {ESSN, DEPENDENT_NAME} because DEPENDENT_NAME is the partial key of DEPENDENT. HNDIT 1105, DBMS By: S.Sabraz Nawaz 6

Step 2: Mapping of Weak Entity Types

ER-to-Relational Mapping Algorithm (contd.) Step 3: Mapping of Binary 1:1 Relation Types o For each binary 1:1 relationship type R in the ER schema, identify the relations S and T that correspond to the entity types participating in R. There are three possible approaches: 1. Foreign Key ( 2 relations) approach: Choose one of the relations-say S-and include a foreign key in S the primary key of T. It is better to choose an entity type with total participation in R in the role of S. Example: 1:1 relation MANAGES is mapped by choosing the participating entity type DEPARTMENT to serve in the role of S, because its participation in the MANAGES relationship type is total. 2. Merged relation (1 relation) option: An alternate mapping of a 1:1 relationship type is possible by merging the two entity types and the relationship into a single relation. This may be appropriate when both participations are total. 3. Cross-reference or relationship relation ( 3 relations) option: The third alternative is to set up a third relation R for the purpose of cross-referencing the primary keys of the two relations S and T representing the entity types. HNDIT 1105, DBMS By: S.Sabraz Nawaz 8

Step 3: Mapping of Binary 1:1 Relation Types

ER-to-Relational Mapping Algorithm (contd.) Step 4: Mapping of Binary 1:N Relationship Types. o For each regular binary 1:N relationship type R, identify the relation S that represent the participating entity type at the N-side of the relationship type. o Include as foreign key in S the primary key of the relation T that represents the other entity type participating in R. o Include any simple attributes of the 1:N relation type as attributes of S. Example: 1:N relationship types WORKS_FOR, CONTROLS, and SUPERVISION in the figure. o For WORKS_FOR we include the primary key DNUMBER of the DEPARTMENT relation as foreign key in the EMPLOYEE relation and call it DNO. An alternative approach is to use a Relationship relation (cross referencing relation) this is rarely done. HNDIT 1105, DBMS By: S.Sabraz Nawaz 10

Step 4: Mapping of Binary 1:N Relationship Types

ER-to-Relational Mapping Algorithm (contd.) Step 5: Mapping of Binary M:N Relationship Types. o For each regular binary M:N relationship type R, create a new relation S to represent R. This is a relationship relation. o Include as foreign key attributes in S the primary keys of the relations that represent the participating entity types; their combination will form the primary key of S. o Also include any simple attributes of the M:N relationship type (or simple components of composite attributes) as attributes of S. Example: The M:N relationship type WORKS_ON from the ER diagram is mapped by creating a relation WORKS_ON in the relational database schema. o The primary keys of the PROJECT and EMPLOYEE relations are included as foreign keys in WORKS_ON and renamed PNO and ESSN, respectively. o Attribute HOURS in WORKS_ON represents the HOURS attribute of the relation type. The primary key of the WORKS_ON relation is the combination of the foreign key attributes {ESSN, PNO}. HNDIT 1105, DBMS By: S.Sabraz Nawaz 12

Step 5: Mapping of Binary M:N Relationship Types

ER-to-Relational Mapping Algorithm (contd.) Step 6: Mapping of Multivalued attributes. o For each multivalued attribute A, create a new relation R. o This relation R will include an attribute corresponding to A, plus the primary key attribute K-as a foreign key in R-of the relation that represents the entity type of relationship type that has A as an attribute. o The primary key of R is the combination of A and K. If the multivalued attribute is composite, we include its simple components. Example: The relation DEPT_LOCATIONS is created. o The attribute DLOCATION represents the multivalued attribute LOCATIONS of DEPARTMENT, while DNUMBER-as foreign key-represents the primary key of the DEPARTMENT relation. o The primary key of R is the combination of {DNUMBER, DLOCATION}. HNDIT 1105, DBMS By: S.Sabraz Nawaz 14

Step 6: Mapping of Multivalued attributes

Result of mapping the COMPANY ER schema into a relational database schema HNDIT 1105, DBMS By: S.Sabraz Nawaz Slide 9-16

ER-to-Relational Mapping Algorithm (contd.) Step 7: Mapping of N-ary Relationship Types. o For each n-ary relationship type R, where n>2, create a new relationship S to represent R. o Include as foreign key attributes in S the primary keys of the relations that represent the participating entity types. o Also include any simple attributes of the n-ary relationship type (or simple components of composite attributes) as attributes of S. Example: The relationship type SUPPY in the ER on the next slide. o This can be mapped to the relation SUPPLY shown in the relational schema, whose primary key is the combination of the three foreign keys {SNAME, PARTNO, PROJNAME} HNDIT 1105, DBMS By: S.Sabraz Nawaz 17

Step 7: Mapping of N-ary Relationship Types

Summary of Mapping constructs and constraints HNDIT 1105, DBMS By: S.Sabraz Nawaz 19

Mapping Exercise-1 Map this schema into a set of relations. An ER schema for a SHIP_TRACKING database. HNDIT 1105, DBMS By: S.Sabraz Nawaz 20

Reference: Elmasri, R., & Navathe, S.B., (2016). Fundamentals of Database Systems. Pearson Education India, 2008. (p. 289 306) HNDIT 1105, DBMS By: S.Sabraz Nawaz 21