Translating an ER diagram to a relational schema

Similar documents
Review: Participation Constraints

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

Lecture 6. SQL, Logical DB Design

Data Modeling. Database Systems: The Complete Book Ch ,

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

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

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

Conceptual Design Using the Entity-Relationship (ER) Model

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

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

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

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

Database Design. Goal: specification of database schema Methodology: E-R Model is viewed as a set of

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

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

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

The Entity-Relationship Model

SQL NULL s, Constraints, Triggers

A Tool for Generating Relational Database Schema from EER Diagram

2. Conceptual Modeling using the Entity-Relationship Model

Chapter 6: Integrity Constraints

Relational Schema Design

Databases and BigData

DATABASE MANAGEMENT SYSTEMS. Question Bank:

SQL DATA DEFINITION: KEY CONSTRAINTS. CS121: Introduction to Relational Database Systems Fall 2015 Lecture 7

CMU - SCS / Database Applications Spring 2013, C. Faloutsos Homework 1: E.R. + Formal Q.L. Deadline: 1:30pm on Tuesday, 2/5/2013

Exercise 1: Relational Model

Databases What the Specification Says

The Relational Data Model: Structure

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

EECS 647: Introduction to Database Systems

The Relational Model. Why Study the Relational Model?

ER modelling, Weak Entities, Class Hierarchies, Aggregation

DENTIST PROJECT. Final Report of Development By Team 12

SQL Simple Queries. Chapter 3.1 V3.0. Napier University Dr Gordon Russell

Database Design and the E-R Model

Winter Winter

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

Oracle Database 10g Express

CSC 742 Database Management Systems

Ch.5 Database Security. Ch.5 Database Security Review

Using SQL Server Management Studio

Data Modeling Basics

IT2304: Database Systems 1 (DBS 1)

IT2305 Database Systems I (Compulsory)

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

Database Design Methodology


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

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

SQL Data Definition. Database Systems Lecture 5 Natasha Alechina

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

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

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

Chapter 1: Introduction. Database Management System (DBMS) University Database Example

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

Lesson 8: Introduction to Databases E-R Data Modeling

The Entity-Relationship Model

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

The Structured Query Language. De facto standard used to interact with relational DB management systems Two major branches

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

Object Oriented Databases. OOAD Fall 2012 Arjun Gopalakrishna Bhavya Udayashankar

Physical Database Design Process. Physical Database Design Process. Major Inputs to Physical Database. Components of Physical Database Design

Introduction to Databases

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

Fundamentals of Database System

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

CS2Bh: Current Technologies. Introduction to XML and Relational Databases. The Relational Model. The relational model

Database Design. Adrienne Watt. Port Moody

Chapter 1: Introduction

Scheme G. Sample Test Paper-I

Database Design and Programming

Relational Database Concepts

Question 1. Relational Data Model [17 marks] Question 2. SQL and Relational Algebra [31 marks]

Rose Data Modeler (logical)

Relationele Databases 2002/2003

Financial Management System

CS 377 Database Systems. Database Design Theory and Normalization. Li Xiong Department of Mathematics and Computer Science Emory University

SpatiaLite Using SQL Views is really simple and easy a very short introduction

Database Design Patterns. Winter Lecture 24

Database Systems. Lecture 1: Introduction

Quiz! Database Indexes. Index. Quiz! Disc and main memory. Quiz! How costly is this operation (naive solution)?

Introduction to SQL ( )


CS 4604: Introduc0on to Database Management Systems. B. Aditya Prakash Lecture #5: En-ty/Rela-onal Models- - - Part 1

CS411 Database Systems

Tutorial 3 The Relational Database Model

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

Fundamentals of Database Design

Section of DBMS Selection & Evaluation Questionnaire

Midterm Exam SOLUTION

ATTACHMENT 6 SQL Server 2012 Programming Standards

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

3. Relational Model and Relational Algebra

The Relational Data Model and Relational Database Constraints

CPS352 Database Systems: Design Project

Chapter 8 The Enhanced Entity- Relationship (EER) Model

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

Preview DESIGNING DATABASES WITH VISIO PROFESSIONAL: A TUTORIAL

Transcription:

Inf1-DA 2010 2011 I: 36 / 117 Translating an ER diagram to a relational schema Given an ER diagram, we can look for a relational schema that closely approximates the ER design. The translation is approximate because it is not always feasible to capture all the constraints in the ER design within the relational schema. (In SQL, certain types of constraint, for example, are inefficient to enforce, and so usually not implemented.) There is more than one approach to translating an ER diagram to a relational schema. Different translations amount to making different implementation choices for the ER diagram. It is possible to make these translations complete (work for any diagram) and automatic (in a push-button graphical tool); but in this course we shall just consider a few examples illustrating some of the main ideas.

Inf1-DA 2010 2011 I: 37 / 117 Mapping entity sets age email Algorithm Create a table for the entity set. Make each attribute of the entity set a field of the table, with an appropriate type. Declare the field or fields comprising the primary key

Inf1-DA 2010 2011 I: 38 / 117 Mapping entity sets age email create table ( char(8), char(20), age integer, email char(15), primary key () )

Inf1-DA 2010 2011 I: 39 / 117 Mapping relationship sets (no key constraints) mark email code year Takes Courses Algorithm Create a table for the relationship set. Add all primary keys of the participating entity sets as fields of the table. Add a field for each attribute of the relationship. Declare a primary key using all key fields from the entity sets. Declare foreign key constraints for all these fields from the entity sets.

Inf1-DA 2010 2011 I: 40 / 117 Mapping relationship sets (no key constraints) mark email code year Takes Courses create table Takes ( char(8), code char(20), mark integer, primary key (, code), foreign key () references, foreign key (code) references Courses )

Inf1-DA 2010 2011 I: 41 / 117 Mapping relationship sets (with key constraints) Directed_By DoS Algorithm Create a table for the relationship set. Add all primary keys of the participating entity sets as fields of the table. Add a field for each attribute of the relationship. Declare a primary key using the key fields from the source entity set only. Declare foreign key constraints for all the fields from the source and target entity sets.

Inf1-DA 2010 2011 I: 42 / 117 Mapping relationship sets (with key constraints) Directed_By DoS create table Directed By ( char(8), staff id char(8), primary key (), foreign key () references, foreign key (staff id) references DoS ) Note that this has captured the key constraint, but not the participation constraint. That requires an alternative approach, and a further kind of declaration.

Inf1-DA 2010 2011 I: 43 / 117 Mapping relationship sets (with key constraints, 2nd method) Directed_By DoS Algorithm Create a table for the source and target entity sets as usual. Add every primary key field of the target as a field in the source. Declare these fields as foreign keys. Because the Directed By relation is many-to-one, we don t in fact need a whole table for the relation itself. However, this does slightly pollute the source entity table.

Inf1-DA 2010 2011 I: 44 / 117 Mapping relationship sets (with key constraints, 2nd method) Directed_By DoS create table ( char(8), char(20), age integer, email char(15), dos id char(8), primary key (), foreign key (dos id) references DoS ) Note that this has still not included the participation constraint on in Directed By, but we are now nearer to doing so...

Inf1-DA 2010 2011 I: 45 / 117 Null values In SQL, a field can have the special value null A null value means that a field is either unknown/missing/unavailable, or undefined/makes no sense here. Some implementations do not allow the null value to appear in primary key fields. They may allow nulls to appear in foreign key fields. Null values can be disallowed from specific fields with a not null declaration. In certain circumstances, by disallowing null, we can enforce a participation constraint.

Inf1-DA 2010 2011 I: 46 / 117 Mapping relationship sets with key+participation constraints Directed_By DoS Algorithm Create a table for the source and target entity sets as usual. Add every primary key field of the target as a field in the source. Declare these fields as not null. Declare these fields as foreign keys.

Inf1-DA 2010 2011 I: 47 / 117 Mapping relationship sets with key+participation constraints Directed_By DoS create table ( char(8), char(20), age integer, email char(15), dos id char(8) not null, primary key (), foreign key (dos id) references DoS )

Inf1-DA 2010 2011 I: 48 / 117 Mapping weak entity sets and identifying relationships number capacity address Rooms Is_Located _In Buildings Algorithm Create a table for the weak entity set. Make each attribute of the weak entity set a field of the table. Add fields for the primary key attributes of the identifying owner. Declare a foreign key constraint on these identifying owner fields. Instruct the system to automatically delete any tuples in the table for which there are no owners

Inf1-DA 2010 2011 I: 49 / 117 Mapping weak entity sets and identifying relationships number capacity address Rooms Is_Located _In Buildings create table Rooms ( number char(8), capacity integer, building char(20), primary key (number,building ), foreign key (building ) references Buildings on delete cascade )

Inf1-DA 2010 2011 I: 50 / 117 Mapping hierarchical entities email Full-Time ISA Part-Time Part-Time Fraction Declare a table as usual for the superclass of the hierarchy. For each subclass declare another table using superclass s primary key and the subclass s extra attributes. Declare the primary key from the superclass as the primary key of the subclass, and with a foreign key constraint.

Inf1-DA 2010 2011 I: 51 / 117 Mapping hierarchical entities email Full-Time ISA Part-Time Part-Time Fraction create table PT ( char(8), pt frac integer, primary key (), foreign key () references )