Mapping ERM to relational database

Slides:



Advertisements
Similar presentations
Convert ER to Relational Database Entity relation Entity relation Attributes attributes Attributes attributes Primary key primary key Primary key primary.
Advertisements

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.
Assignment Design Methodology A structured approach that uses procedures, techniques, tools, and documentation aids to support and facilitate the.
Logical Database Design
Entity Relationship (ER) Modeling
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 4 Entity Relationship (ER) Modeling.
Entity Relationship (ER) Modeling
Entity Relationship (ER) Modeling
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.
Chapter 6 Methodology Logical Database Design for the Relational Model Transparencies © Pearson Education Limited 1995, 2005.
Methodology Logical Database Design for the Relational Model
1 © Prentice Hall, 2002 Chapter 5: Logical Database Design and the Relational Model Modern Database Management 6 th Edition Jeffrey A. Hoffer, Mary B.
Mapping from E-R Model to Relational Model Yong Choi School of Business CSUB.
Chapter 4 Entity Relationship (ER) Modeling
Database Systems: Design, Implementation, and Management Tenth Edition
 Keys are special fields that serve two main purposes: ◦ Primary keys are unique identifiers of the relation in question. Examples include employee numbers,
Chapter 3 Relational Model Chapter 4 in Textbook.
Chapter 5 1 © Prentice Hall, 2002 Chapter 5: Transforming EER Diagrams into Relations Mapping Regular Entities to Relations 1. Simple attributes: E-R attributes.
Chapter 7 Data Modeling with Entity Relationship Diagrams Database Principles: Fundamentals of Design, Implementation, and Management Tenth Edition.
Mapping from Data Model (ERD) to Relational Model Yong Choi School of Business CSUB.
Chapter 5 Entity Relationship (ER) Modelling
Chapter 5 Entity–Relationship Modeling
Mapping from Data Model (ERD) to Relational Model
Normalization A technique that organizes data attributes (or fields) such that they are grouped to form stable, flexible and adaptive entities.
Team Dosen UMN Database Design Connolly Book Chapter
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 4 Entity Relationship (ER) Modeling.
Chapter 4 Entity Relationship (ER) Modeling.  ER model forms the basis of an ER diagram  ERD represents conceptual database as viewed by end user 
MIS 3053 Database Design & Applications The University of Tulsa Professor: Akhilesh Bajaj ER Model Lecture 4 Mapping an ER model to tables © Akhilesh Bajaj,
CS 370 Database Systems Lecture 9 The Relational model.
Initial Design of Entity Types for the COMPANY Database Schema Based on the requirements, we can identify four initial entity types in the COMPANY database:
IMS 4212: Data Modeling—More Relationships 1 Dr. Lawrence West, Management Dept., University of Central Florida Data Modeling—Topics.
Database Design – Lecture 5 Conceptual Data Modeling – adding attributes.
3 & 4 1 Chapters 3 and 4 Drawing ERDs October 16, 2006 Week 3.
Chapter 9: Logical Database Design and the Relational Model (ERD Mapping)
1 © Prentice Hall, 2002 Chapter 5: Logical Database Design and the Relational Model Modern Database Management 6 th Edition Jeffrey A. Hoffer, Mary B.
3 & 4 1 Database Systems: Design, Implementation, & Management, 7 th Edition, Rob & Coronel Keys Consists of one or more attributes that determine other.
Database Systems: Design, Implementation, and Management Ninth Edition Chapter 4 Entity Relationship (ER) Modeling.
Mapping from conceptual model (EER-M)
1 Chapter 17 Methodology - Local Logical Database Design.
1 CS 430 Database Theory Winter 2005 Lecture 15: How to Convert an ER Model to Relations.
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 4 ENTITY RELATIONSHIP (ER) MODELING Instructor Ms. Arwa Binsaleh 1.
Chapter 9 Logical Database Design : Mapping ER Model To Tables.
Chapter 17 Logical Database Design for the Relational Model Pearson Education © 2009.
Software School of Hunan University Database Systems Design Part III : Mapping ER Diagram to Relational Schema.
Database Design – Lecture 6 Moving to a Logical Model.
Week 7-8 DBMS ER-Relational Mapping. ER-Relational Mapping.
Lecture4: Informal guidelines for good relational design Mapping ERD to Relation Prepared by L. Nouf Almujally Ref. Chapter3 Lecture4 1.
Quiz Where to Store Attributes of Relationship Staff (1) Interviews (0..*) Client Attributes: date, time, comment Staff (StaffNo, …) PK: StaffNo.
1 © Prentice Hall, 2002 ITD1312 Database Principles Chapter 4B: Logical Design for Relational Systems -- Transforming ER Diagrams into Relations Modern.
Logical Database Design and the Relational Model.
Database Design Slide 1 Database Design Lecture 7 part 2 Mapping ERD to Tables.
Mapping ER to Relational Model Each strong entity set becomes a table. Each weak entity set also becomes a table by adding primary key of owner entity.
Logical Design 12/10/2009GAK1. Learning Objectives How to remove features from a local conceptual model that are not compatible with the relational model.
Methodology - Logical Database Design. 2 Step 2 Build and Validate Local Logical Data Model To build a local logical data model from a local conceptual.
1 The Relational Data Model David J. Stucki. Relational Model Concepts 2 Fundamental concept: the relation  The Relational Model represents an entire.
Lecture # 14 Chapter # 5 The Relational Data Model and Relational Database Constraints Database Systems.
Database Designsemester Slide 1 Database Design Lecture 7 Entity-relationship modeling Text , 7.1.
Methodology Logical Database Design for the Relational Model
Chapter 4: Part B Logical Database Design and the Relational Model
Logical Database Design for the Relational Model
Chapter Design Methodology Pearson Education © 2009.
Tables and Their Characteristics
Database Design – Lecture 4
Entity-Relationship Modelling
Relational Database Design by ER- and EER-to-Relational Mapping
Entity-Relationship Modelling
CHAPTER 4: LOGICAL DATABASE DESIGN AND THE RELATIONAL MODEL
DBMS ER-Relational Mapping
Mapping an ERD to a Relational Database
Mapping an ERD to a Relational Database
Presentation transcript:

Mapping ERM to relational database Mapping the ER model to the relational model Logical Database Design Reading: e.g. Connolly/Begg DB systems: (4th ed) Ch 16 – step 2.2 and/or (3rd ed) Ch 15.1 Rob et al: Section 11.2

What does this ERM model? Work with your neighbour and identify: Entities (strong, weak) Attributes (simple, composite, derived, multi-valued) Relationships (cardinality, participation, attributes)

Mapping the conceptual model Step-by-step “cookbook recipe” Details how to create a logical (relational) model from a conceptual (ERM) model Main ideas: Entity with attributes  Relation with fields Relationship  Foreign key Let’s start with the steps we need for the books example

Steps 1&2: Entities For each entity type create a relation include all simple attributes include composite attributes: usually use one field per component, or single field Leave out multi-valued attributes Strong entity: Choose a primary key Weak entity: will get its primary key later Now apply this to the books example

Mapping binary relationships Identify one entity as “parent” other entity as “child” as general rule, PK of parent is added to child as FK Any attributes of the relationship are added to child relation

Step 3: (1:*) Relationships Relation at “1” end is parent Relation at “many” end is child include parent's PK in child as foreign key. Any attributes of the relationship are added to child Apply this to the (1:*) relationships in the books example now Note: for recursive (1:*) relationships, use same rule. Add primary key of the relation a second time as foreign key

Step 7: (*:*) relationships For each binary many-to-many relationship type create a new relation. Add PKs of both “parents” to the new relation (as FKs) and also any attributes of the relationship. PK of the new relation is usually composite: simply combine both FKs. If this is not unique, include additional fields as needed Apply this to the (1:*) relationships in the books example now Note: Apply same method for unary *:*: create a new table, with two foreign keys both linking to the original PKs

Step 9: Multi-valued attributes For each multi-valued attribute: create a new relation that contains the attribute itself, plus the primary key of the “parent” entity as foreign key. The primary key of the new relation is usually made up of all its attributes. Sometimes, not all attributes may be needed Apply this to the books ERM now

Steps Summary (from Connolly/Begg) 1. Strong entities 2. Weak entities 3. Binary 1:* relationships 4. Binary 1:1 relationships 5. Recursive 1:1 relationships 6. Super- and subclasses  later!! 7. Binary *:* relationships 8. Complex relationships 9. Multi-valued attributes Check: all relations have PK; there are at least (n-1) FKs if you have n relations, and all relations are in 3NF

Steps Summary (from Rob et al) 1. Strong entities 2. Weak entities 3. Multi-valued attributes 4. Binary relationships 1:* 1:1 (also discusses 1:1 recursive) *:* 5. Ternary relationships 6. Super- and subclasses  later!! How does that compare with Connolly/Begg? Which do you prefer?

Step 8: complex relationships For each ternary (and higher order) relationship: Create a new relation made up of the primary keys from the n participating relations, as foreign keys plus any attributes of the relationship. PK of the new relation usually the combination of all FKs But may be able to use just a subset of the attributes Or may need to add in other attributes to guarantee uniqueness.

Step 8 Example 1..* 1.* Orders 1..* Map this ERM now! Customer custID {PK} name 1..* Supplier suppID {PK} name address Product prodID {PK} type name Orders 1.* 1..* date quantity Map this ERM now!

Step 4: Binary (1:1) Three options, depending on participation Option A (mandatory participation on both sides): Merge both entities into a single entity choose either of the original PKs as the new PK include any attributes of the relationship Option B (mandatory participation on one side): relation with optional participation is parent Relation with mandatory participation is child add PK of parent to child as FK. add any attribute of the relationship to child

Step 4: Binary (1:1) ctd. Option C (optional participation on both sides) Arbitrarily choose one entity as child, the other as parent proceed as usual - add PK of parent to child as FK; also add any attributes of the relationship also use this option if mandatory participation on both sides and want to keep separate relations If one entity is close to mandatory participation, choose that one as child.

Step 4 Example Manages 1..1 0..1 “Each branch has one manager, each manager may manage a branch (but those at head office don’t)” Manager managerID {PK} name salary Branch bName {PK} address phone How would you map this?

Step 5: Unary (Recursive) 1:1 Follow Step 4 in principle, but same entity on both sides of relationship Mandatory participation both sides keep single relation add new attribute - “copy” of PK, to act as FK Optional on both sides create a new relation with just two copies of PK. They act as composite PK and separately as FKs to link back to entity Optional one side follow either of the two methods above.

Step 5 example 1..1 “Each staff member has one supervisor and may supervise one staff member” Supervises Staff ID {PK} name department 0..1 One relation: Staff(ID, supervisorID*, name, department) Or Two relations: Staff(ID, name, department) Supervision(staffID*, supervisorID*)

Directed Reading or Connolly/Begg “Database Systems” (4th ed) Ch 16 – step 2.2 or (3rd ed) Ch 15.1 Ignore “Step 6” (super- and sub-classes) for now or Connolly/Begg “Database Solutions” Chapter 10 – step 2.1 Rob et al: Section 11.2 ***************************************************************** Note that if you read any other database textbook or access any websites you may see other descriptions of the mapping “recipe”. They all do the same thing! We use the numbering of Connolly and Begg DB Systems. DB solutions uses the same method but no numbering.

What about unary (recursive) relationships? Textbooks usually discuss recursive 1:1 relationships explicitly Often don't mention 1:* or *:* recursive relationships Essentially, treat all recursive relationships like the equivalent binary ones, except the entities at both ends are one and the same.

Summary Follow 9 Step procedure should result in a “good” relational model, i.e. at least in 3rd Normal Form Be careful!!! Remember to identify Primary Keys For relationships: Identify one relation as “parent”, one as “child” post parent’s PK to child as FK

Summary ctd. In the relational model, entities are represented as relations simple attributes are represented as fields multi-valued attributes represented as a relation derived attributes are not usually stored Composite attributes are usually split into several fields relationships are represented indirectly through the use of foreign keys 1:1 relationship  foreign key or single relation 1:* relationship  foreign key in “child” *:* relationship  relation and two foreign keys