ER to Relational Mapping

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

2. Conceptual Modeling using the Entity-Relationship Model

Relational Schema Design

Data Modeling. Database Systems: The Complete Book Ch ,

A Tool for Generating Relational Database Schema from EER Diagram

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

Review: Participation Constraints

A Rational Software Whitepaper

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

Chapter 8 The Enhanced Entity- Relationship (EER) Model

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

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

Lecture 6. SQL, Logical DB Design

Conceptual Design Using the Entity-Relationship (ER) Model

CSC 742 Database Management Systems

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

SQL DDL. DBS Database Systems Designing Relational Databases. Inclusion Constraints. Key Constraints

Database Design Methodology

Databases and BigData

Big Data: Pig Latin. P.J. McBrien. Imperial College London. P.J. McBrien (Imperial College London) Big Data: Pig Latin 1 / 36

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

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

ER modelling, Weak Entities, Class Hierarchies, Aggregation

Databases What the Specification Says

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

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


IT2304: Database Systems 1 (DBS 1)

Relational Database Concepts

The Entity-Relationship Model

The Entity-Relationship Model

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

CSC 443 Data Base Management Systems. Basic SQL

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

Entity - Relationship Modelling

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

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

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

Rose Data Modeler (logical)

Umbrello UML Modeller Handbook

RELATIONSHIP STRENGTH

Requirement Analysis & Conceptual Database Design. Problem analysis Entity Relationship notation Integrity constraints Generalization

IV. The (Extended) Entity-Relationship Model

The Entity-Relationship Model

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

SQL Server An Overview

Graham Kemp (telephone , room 6475 EDIT) The examiner will visit the exam room at 15:00 and 17:00.

DBMS Questions. 3.) For which two constraints are indexes created when the constraint is added?

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

ER & EER to Relational Mapping. Chapter 9 1

Intermediate SQL C H A P T E R4. Practice Exercises. 4.1 Write the following queries in SQL:

IT2305 Database Systems I (Compulsory)

Database Design. Adrienne Watt. Port Moody

How To Create A Table In Sql (Ahem)

The Relational Data Model: Structure

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

Online shopping cart. Tarik Guelzim Graduate school of computer science at Monmouth University. CS517 Database management systems Project 2

XV. The Entity-Relationship Model

There are five fields or columns, with names and types as shown above.

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

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

In This Lecture. SQL Data Definition SQL SQL. Notes. Non-Procedural Programming. Database Systems Lecture 5 Natasha Alechina

Schema Advisor for Hybrid Relational/XML DBMS

Chapter 6: Integrity Constraints

Introduction This document s purpose is to define Microsoft SQL server database design standards.

Relational Database Basics Review

More on SQL. Juliana Freire. Some slides adapted from J. Ullman, L. Delcambre, R. Ramakrishnan, G. Lindstrom and Silberschatz, Korth and Sudarshan

The SQL Query Language. Creating Relations in SQL. Referential Integrity in SQL. Basic SQL Query. Primary and Candidate Keys in SQL

Graphical Systems Modeling with UML / SysML Class diagrams

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

The Relational Data Model and Relational Database Constraints

Database Design Methodology

Once the schema has been designed, it can be implemented in the RDBMS.

New York University Computer Science Department Courant Institute of Mathematical Sciences

EECS 647: Introduction to Database Systems

Polymorphic Data Modeling

Database Modelling in UML

4 Logical Design : RDM Schema Definition with SQL / DDL

Entity-Relationship Model. Purpose of E/R Model. Entity Sets

CIS 631 Database Management Systems Sample Final Exam

Lesson 8: Introduction to Databases E-R Data Modeling

CPS352 Database Systems: Design Project

Below is a table called raw_search_log containing details of search queries. user_id INTEGER ID of the user that made the search.

DataBase Management Systems Lecture Notes

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

Doing database design with MySQL

4 Simple Database Features

Introduction to Database Development

Database Design Process. ER Model. Goals. Relational Model. SQL - The Language of Databases. IT420: Database Management and Organization

BİL 354 Veritabanı Sistemleri. Entity-Relationship Model

Logical Schema Design: The Relational Data Model

Grocery Store Project

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

Working with DB2 UDB objects

Fundamentals of Database Design

Schema Evolution in SQL-99 and Commercial (Object-)Relational DBMS

11 November

!"# $ %& '( ! %& $ ' &)* + ! * $, $ (, ( '! -,) (# *&23. mysql> select * from from clienti;

SQL NULL s, Constraints, Triggers

Chapter 2: Entity-Relationship Model

Transcription:

ER to Relational Mapping P.J. M c.brien Imperial College London P.J. M c.brien (Imperial College London) ER to Relational Mapping 1 / 13

Designing a Relational Database Schema How do you design a relational database schema for a particular UoD? 1 Need some way to model the semantics of the UoD as a conceptual schema ER (many variants exist) UML class diagrams 2 Need to map the ER/UML schema into a relational schema 3 Need to ensure that the relational schema is a good design Normalisation P.J. M c.brien (Imperial College London) ER to Relational Mapping 2 / 13

Semantic Modelling: ER Schemas CREATE TABLE branch ( sortcode INTEGER NOT NULL, bname VARCHAR(20) NOT NULL, cash DECIMAL(10,2) NOT NULL, sortcode bname cash CONSTRAINT branch pk PRIMARY KEY (sortcode) ) CREATE TABLE account ( no INTEGER NOT NULL, type CHAR(8) NOT NULL, cname VARCHAR(20) NOT NULL, rate DECIMAL(4,2) NULL, sortcode INTEGER NOT NULL, CONSTRAINT account pk PRIMARY KEY (no), no type cname rate? CONSTRAINT account fk FOREIGN KEY (sortcode) REFERENCES branch ) branch 0:N holds 1:1 account 0:N has 1:1 movement mid tdate amount CREATE INDEX account type ON account (type) CREATE TABLE movement ( mid INTEGER NOT NULL, no INTEGER NOT NULL, amount DECIMAL(10,2) NOT NULL, tdate DATETIME NOT NULL, CONSTRAINT movement pk PRIMARY KEY (mid), CONSTRAINT movement fk FOREIGN KEY (no) REFERENCES account ) P.J. M c.brien (Imperial College London) ER to Relational Mapping 3 / 13

Mapping an ER Schema to a Relational Schema Borrowing the terminology of object relational mapping (ORM) table per type (TPT) Each ER entity is mapped to a corresponding single relation, with all directly connected attributes and relationships of that entity. table per hierarchy (TPH) Each ER entity that is not a subclass of another ER entity is mapped to a single relation with all the data of the subclasses in the same table. table per concrete type (TPC) Each ER entity is mapped to a corresponding single relation, with all attributes and relationships of any superclasses included in that relation. table per modelling construct (TPM) Store all objects in the ER Schema in a fixed set of tables in a relational model for the various ER modelling constructs. P.J. M c.brien (Imperial College London) ER to Relational Mapping 4 / 13

Mapping ER KLOS to a relational model: entities and attributes Taking a TPT approach, there is a simple mapping of entities and attributes to tables and columns: 1 Each entity E maps to a table R E 2 Each attribute A maps to a column C A of R E 3 If A is an optional attribute, then C A is nullable, otherwise C A is not nullable 4 If K are key attribute(s), then C K are a key of R E Tables generated from entities person department salary number name bonus? dname person(salary number, name, bonus?) department(dname) P.J. M c.brien (Imperial College London) ER to Relational Mapping 5 / 13

Mapping ER KLOS to a relational model: relationships Taking a TPT approach, for each relationship R between E 1, E 2, entities E 1, E 2 map to R 1, R 2 as before, and 1 If R is a many-many relationship then it maps to 1 a table R R 1 R 2 ( K 1, K 2 ) 2 a foreign key R R 1 R 2 ( K 1 ) R 1 ( K 1 ) 3 a foreign key R E 1 E 2 ( K 2 ) E 2 ( K 2 ) 2 If R is a one-many relationship then it maps to 1 a column K 2 in R 1 2 a foreign key R 1 ( K 2 ) R 2 ( K 2 ) 3 if the participation of E 1 in R is optional, then K 2 is an optional column of R 1 Tables generated from relationships name bonus? person salary number 1:1 works in dname 0:N department person(salary number, name, bonus?, dname) department(dname) person(dname) department(dname) P.J. M c.brien (Imperial College London) ER to Relational Mapping 6 / 13

Mapping ER KLOS to a relational model: subsets Taking a TPT approach, for each subset E s of E, entities E s, E map to tables R s, R as before and: 1 a key K in R s (where K is the key of R) 2 a foreign key R s( K) R( K) Tables generated from subsets mobile number bonus? salary number name manager person person(salary number, name, bonus?) manager(salary number, mobile phone) manager(salary number) person(salary number) P.J. M c.brien (Imperial College London) ER to Relational Mapping 7 / 13

Mapping ER KLOS to a relational model P.J. M c.brien (Imperial College London) ER to Relational Mapping 8 / 13

Mapping ER D to a relational model Taking a TPT approach, if E is a generalisation of E 1,..., E n, then entities E 1,..., E n, E map to tables R 1,..., R n, R as before and: 1 treat each E x E 1,..., E n as a subset of E 2 no implementation of disjointness using just PKs and FKs Tables generated from generalisations pigeon hole bonus? name non email user person messages email user salary number email person(salary number, name, bonus?) non email user(salary number, pigeon hole) non email user(salary number) person(salary number) email user(salary number, email) email user(salary number) person(salary number) P.J. M c.brien (Imperial College London) ER to Relational Mapping 9 / 13

Mapping ER W to a relational model If E W is a weak entity that maps to a relation R W, the foreign key R K due to the participation in a relationship is also used in the key of R K Tables generated from weak entities issue swipe card 1:1 for 0:N person bonus? salary number name person(salary number, name, bonus?) swipe card(salary number, issue) swipe card(salary number) person(salary number) P.J. M c.brien (Imperial College London) ER to Relational Mapping 10 / 13

Mapping ER H to a relational model Rules for binary relationship R between E 1, E 2 generalise to rules for R between E 1,..., E n Tables generated from n-ary entities salary number manager dname 0:N person works 0:N in 0:N department person(salary number) manager(salary number) manager(salary number) person(salary number) department(dname) works in(person salary number, manager salary number, dname) works in(person salary number) person(salary number) works in(manager salary number) manager(salary number) works in(dname) department(dname) P.J. M c.brien (Imperial College London) ER to Relational Mapping 11 / 13

Mapping ER A to a relational model Attributes of a relationship go on the same table as that which implements the relationship Tables generated from attrbutes of relationships salary number start date end date? dname person 0:N works in 0:N department person(salary number) department(dname) works in(salary number, dname, start date, end date?) works in(salary number) person(salary number) works in(dname) department(dname) P.J. M c.brien (Imperial College London) ER to Relational Mapping 12 / 13

Mapping ER ADHKLOSW to a relational model P.J. M c.brien (Imperial College London) ER to Relational Mapping 13 / 13