Transformation of an ER Model into a Relational Database Schema Translating to Software.

Slides:



Advertisements
Similar presentations
Three-Step Database Design
Advertisements

Conceptual / semantic modelling
Database Design: ER Modelling (Continued)
Logical DB Design: ER to Relational Entity sets to tables. Employees ssn name lot CREATE TABLE Employees (ssn CHAR (11), name CHAR (20), lot INTEGER, PRIMARY.
Data Modeling. What are you keeping track of? You begin to develop a database by deciding what you are going to keep track of. Each thing that you are.
1 SA0951a Entity-Relationship Modelling. 2 What is it about? ER model is used to show the Conceptual schema of an organisation. Independent of specific.
Transform an ER Model into a Relational Database Schema
the Entity-Relationship (ER) Model
Relational Database Design Via ER Modelling
Relational Database. Relational database: a set of relations Relation: made up of 2 parts: − Schema : specifies the name of relations, plus name and type.
Database Processing: Fundamentals, Design, and Implementation, 9/e by David M. KroenkeChapter 5/1 Copyright © 2004 Please……. No Food Or Drink in the class.
SQL Lecture 10 Inst: Haya Sammaneh. Example Instance of Students Relation  Cardinality = 3, degree = 5, all rows distinct.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 6 Advanced Data Modeling.
Database Systems: Design, Implementation, and Management Tenth Edition
BIS Database Systems School of Management, Business Information Systems, Assumption University A.Thanop Somprasong Chapter # 6 Advanced Data Modeling.
Chapter 5 Understanding Entity Relationship Diagrams.
Mapping an ERD to a Relational Database To map an ERD to a relational database, five rules are defined to govern how tables are constructed. 1)Rule for.
Data Modeling and Relational Database Design ISYS 650.
Fundamentals, Design, and Implementation, 9/e COS 346 Day 8.
System Analysis - Data Modeling
Fundamentals, Design, and Implementation, 9/e Chapter 5 Database Design.
McGraw-Hill/Irwin Copyright © 2007 by The McGraw-Hill Companies, Inc. All rights reserved. Chapter 5 Understanding Entity Relationship Diagrams.
Concepts of Database Management Seventh Edition
CS424 PK, FK, FD Normalization Primary and Foreign Keys Primary and foreign keys are the most basic components on which relational theory is based. Primary.
Michael F. Price College of Business Chapter 6: Logical database design and the relational model.
Mapping ERM to relational database
Ch5: ER Diagrams - Part 2 Much of the material presented in these slides was developed by Dr. Ramon Lawrence at the University of Iowa.
Lecture 2 The Relational Model. Objectives Terminology of relational model. How tables are used to represent data. Connection between mathematical relations.
Chapter 4 The Relational Model.
MIS 385/MBA 664 Systems Implementation with DBMS/ Database Management Dave Salisbury ( )
Switch off your Mobiles Phones or Change Profile to Silent Mode.
Concepts and Terminology Introduction to Database.
Chapter 2 Adapted from Silberschatz, et al. CHECK SLIDE 16.
SQL Structured Query Language Programming Course.
Chapter 8 Data Modeling Advanced Concepts Database Principles: Fundamentals of Design, Implementation, and Management Tenth Edition.
Relational Data Model Ch. 7.1 – 7.3 John Ortiz Lecture 3Relational Data Model2 Why Study Relational Model?  Most widely used model.  Vendors: IBM,
1.  An introduction to data modelling  The purpose of data modelling  Modelling data relationships 2.
Concepts of Database Management Sixth Edition Chapter 6 Database Design 2: Design Method.
The Relational Model1 ER-to-Relational Mapping and Views.
Concepts of Database Management, Fifth Edition Chapter 6: Database Design 2: Design Methodology.
Chapter 9 Logical Database Design : Mapping ER Model To Tables.
Announcements Reading for Monday –4.6 Homework 3 – Due 9/29.
Computing & Information Sciences Kansas State University Friday, 26 Sep 2008CIS 560: Database System Concepts Lecture 13 of 42 Friday, 26 September 2008.
CSE314 Database Systems Lecture 3 The Relational Data Model and Relational Database Constraints Doç. Dr. Mehmet Göktürk src: Elmasri & Navanthe 6E Pearson.
Lecture 3 Book Chapter 3 (part 2 ) From ER to Relational.
advanced data modeling
DBMS ER model-2 Week 6-7.
Entity Relationship Diagram (ERD). Objectives Define terms related to entity relationship modeling, including entity, entity instance, attribute, relationship.
Database Design Slide 1 Database Design Lecture 7 part 2 Mapping ERD to Tables.
Lecture 03 Constraints. Example Schema CONSTRAINTS.
Ch 05. Basic Symbols ( manino ). Cardinalities Cardinality Notation.
Chapter 5 Understanding Entity Relationship Diagrams.
Department of Mathematics Computer and Information Science1 CS 351: Database Management Systems Christopher I. G. Lanclos Chapter 4.
Database Design, Application Development, and Administration, 6 th Edition Copyright © 2015 by Michael V. Mannino. All rights reserved. Chapter 5 Understanding.
Chapter 3 The Relational Model. Why Study the Relational Model? Most widely used model. Vendors: IBM, Informix, Microsoft, Oracle, Sybase, etc. “Legacy.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 The Relational Model Chapter 3.
1 The Relational Data Model David J. Stucki. Relational Model Concepts 2 Fundamental concept: the relation  The Relational Model represents an entire.
1 CS122A: Introduction to Data Management Lecture #4 (E-R  Relational Translation) Instructor: Chen Li.
Lecture # 14 Chapter # 5 The Relational Data Model and Relational Database Constraints Database Systems.
ER Diagrams ● Many different notations are available ● From wikipedia:wikipedia: Entity-relationship modelwikipedia: Entity-relationship model ● How do.
Transformation of an ER Model into a Relational Database Schema Translating to Software.
Logical Database Design and the Rational Model
Relational Database Design by ER- and EER-to- Relational Mapping
Tables and Their Characteristics
From ER to Relational Model
The Relational Model Textbook /7/2018.
Mapping an ERD to a Relational Database
INSTRUCTOR: MRS T.G. ZHOU
Database Dr. Roueida Mohammed.
Mapping an ERD to a Relational Database
Presentation transcript:

Transformation of an ER Model into a Relational Database Schema Translating to Software

2 into 1 won’t go? ER model has 2 major concepts –Entities –Relationships Relational model has 1 major concept –Relation (table) There are general rules for translation –good implementations come from these and experience/inventiveness –inventiveness requires clear understanding of the relational model

How we do it Entities –all become relations (tables) Relationships –some become relations (tables) –some are implemented by use of PK, FK –some need additional coding using DBMS facilities using application code if necessary –we know which by their cardinality signatures

Notation Primary key attribute(s): underline & bold Foreign key attributes: * #: Unique attribute indicator –traditional usage, helps identify keys in simplified examples A# is the PK of relation A

Entities to Relations Start off by representing each entity class as a relation Add the attributes Indicate primary key Do it for hospital example

Hospital Example PATIENT{P#,PName,PAddress,Dob,Sex} P_PATIENT{P#} WARD{W#,WType} NURSE{N#,Name,Grade} OPERATION{Op#,Type,Date,Time} SURGEON{Sname,SAddress,Tel#} CONSULTANT{Cname,Speciality} THEATRE{T#,TheatreType} Attributes added for illustration - not all justified by our spec.

Relationships to Relations In lectures we will –Look at 3 simple cardinality signatures common easy to translate no problems –Look at some problem cases for illustration –Look at a comprehensive list of signatures for revision and exercise for completeness –Return for more later!

Simple case 1 A(A#, …) B(B#, A#*, …) BA * * 1:N Optional on the “many side” Rule Plant the primary key of the one side into the many side

Simple Case 1 - example

Simple case 2 A(A#, …) B(B#, …) BA 0..* N:M Optional on both sides Rule Create a relation to represent the relationship Plant both primary keys in it as the joint primary key R(A#*, B#*)

Simple Case 2 - example

Simple Case 2 - comments The existence of a tuple in the “intersection” relation is the relationship instance The key is joint because a student can only take a module once –SID as PK would let a student do only 1 module –CODE as PK would let a module have only 1 student

Simple case 3 A(A#, …) B(B#, …) BA * 1:N Optional on both sides Rule Create a relation to represent the relationship Plant both primary keys in it Make the many side key the new PK R(A#*,B#*)

Simple Case 3 - example

Simple Case 3 - comments Again, the existence of a tuple in the “intersection” relation is the relationship instance The intersection PK is only one FK (student) –SID is PK so each student can have max 1 Sponsoring –CO not PK, Sponsor could have many Sponsorings

Relationships to Relations Simple Summary Bring keys of associated entities together by –If there is a “one” side if Mandatory –posting key as foreign key into an existing “host” relation if Optional –creating a new relation posting both keys to it –set PK to implement the multiplicity »(the entity which can have only 1) –If there are 2 “many” sides creating a new relation posting both keys to it set both as a joint PK

Problem cases

Problem case 1 BA * 1:N Mandatory on both sides Situation 1..* is our problem –the tell-tale signature Can do no better than the optional case –Plant the key of A in B A(A#, …) B(B#, A#*, …)

Problem Case 1 - example ModuleLecturer * *

Problem case 1 - comments How can we ensure that every instance of A is involved in at least one relationship with a B? –i.e. every A# appears in B Cannot enforce it Can check if rule is obeyed (rel. algebra) A[A#] == B[A#] Can query for As not found in B –could query for operators not found in tours –could list lecturers not teaching

Problem case 2 BA 0..* 1..* N:M Mandatory on one of the sides Situation 1..* again Can do no better than the optional case –Plant the key of A and B in a new relation and joint PK A(A#, …) B(B#, …)R(A#*, B#*)

Problem case 2 - comments How can we ensure that every instance of A (every A#) is involved in at least one relationship with a B? (same question) Cannot enforce it (same problem!) Every A# must appear in R at last once Can check if rule is obeyed (rel. algebra) A[A#] == R[A#] Can query for As not found in R etc.

Problem cases - general These cases are the less common ones Often the constraints cannot be implemented for all time –modules and students before registration? Often left unimplemented –but with a mechanism to list breaches a query, run regularly or on demand Enforcing participation may just not be important

Comprehensive list of signatures

1:N Relationships A(A#,...) B(B#, A#*,...) A(A#,…) B(B#,…) R(A#*,B#*) A(A#,…) B(B#, A#*,…) A(A#,…) B(B#,...) R(A#*,B#*) BA * * BA * *

Binary (M:N) Relationships A(A#,…) B(B#,…) R(A#*,B#*) A(A#,...) B(B#,...) A(A#,…) B(B#,…) A(A#,…) B(B#,...) R(A#*,B#*) BA 1..*0..* 1..* 0..* BA 1..*0..* 1..* BA

Binary (1:1) Relationships A(A#,…) B(B#,…) R(A#*,B#*) or R(A#*,B#*) A(A#,…) B(B#, A#*…) A(A#,…) B(B#, A#*…) c.f. above A  B Not Null & No Duplicates Not Null & No Duplicates No Duplicates No Duplicates BA 1..1

Schema semantics For the 12 cases there are only 3 different relational schemas 1..* is the problem –ensuring minimal participation –(also 1..1) ensuring two way participation there may be a chicken and egg problem here –do we really want it? –we may have only one entity really

Two alternative ideas

Idea 1 N:M and the Relational Model Just not supported We have always needed a third table Is that an entity we missed? –Matter of opinion (“takes” or “Registration”) May want to represent N:M on the ER –makes sense to the user Any N:M can be decomposed to two 1:N

M:N Decomposition A(A#, …) B(B#, …) This is exactly the same relational schema as for the M:N relationship below. R(A#*, B#*, …) Note: A pair of M:N’s leads to a fan trap.

Modified ER? After the ER model is agreed: –Make systematic changes to move it towards the relational model replace N:M replace optional 1:N C&B, recommend this stage –DB Sol n, “Step 1.7”, p147 et.seq. –DB Sys, Chapt. 8

Hospital ER 0..* 1..1 treats 0..* 1..1 occupies 0..* 0..1 inWard 0..* 0..1 inTheatre 0..*1..1undergoes 0..* 1..1 located 0..* 1..1 performs 0..* assists 0..* 0..1 supervises Consultant Surgeon Operation Theatre Nurse Ward Patient P Patient

Hospital ER

Idea 2 Null foreign keys for “optional” 1:N We have been creating intersection relations We can treat it as the mandatory case but give the foreign key no value Lots of blanks where there is no relationship

Null foreign key - example c.f. Simple case 3 - example there’s an alternative

Translation Summary (for now) Entities become relations Some relationships become relations 1..* is hard –i.e. most mandatory participation It is not quite a “recipe” –design choices –ingenuity

Subtype Relationships We will return to these