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.

Slides:



Advertisements
Similar presentations
Week 5 Relational Database Design by ER- -to-Relational Mapping.
Advertisements

1 Database Theoretic Basis Entity Relationship (E-R) Modeling Database Theoretic Basis Entity Relationship (E-R) Modeling.
Data modeling using the entity-relationship model Sept. 2012Yangjun Chen ACS Outline: Data modeling using ER-model (Chapter 3 - 3rd, 4th, 5th ed.)
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 7 Data Modeling Using the Entity- Relationship (ER) Model.
Review Database Application Development Access Database Development ER-diagram Forms Reports Queries.
Data modeling using the entity-relationship model Winter 2006Ron McFadyen Entity-relationship model (ER model) P. 49: “This model and its variations.
Mapping ERM to relational database
 Keys are special fields that serve two main purposes: ◦ Primary keys are unique identifiers of the relation in question. Examples include employee numbers,
Data Modeling Using the Entity-Relationship Model
ER- and EER-to-Relational Mapping
Lecture4: Informal guidelines for good relational design Mapping ERD to Relation Ref. Chapter3 Lecture4 1.
© 2007 by Prentice Hall (Hoffer, Prescott & McFadden) 1 Entity Relationship Diagrams (ERDs)
CSE314 Database Systems Data Modeling Using the Entity- Relationship (ER) Model Doç. Dr. Mehmet Göktürk src: Elmasri & Navanthe 6E Pearson Ed Slide Set.
1 DATABASE By Mr. Abdalla A. Shaame.  What is a database?  The main characters of a database system  The basic database design method  The entity-relationship.
Chapter 5 1 © Prentice Hall, 2002 Chapter 5: Transforming EER Diagrams into Relations Mapping Regular Entities to Relations 1. Simple attributes: E-R attributes.
Database. Basic Definitions Database: A collection of related data. Database Management System (DBMS): A software package/ system to facilitate the creation.
Database. Basic Definitions Database: A collection of related data. Database Management System (DBMS): A software package/ system to facilitate the creation.
Review: Application of Database Systems
Chapter 5 Entity–Relationship Modeling
SQL Structured Query Language Programming Course.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 3 Data Modeling Using the Entity- Relationship (ER) Model.
Data Modeling Using the Entity- Relationship (ER) Model.
Chapter 7: Modeling Data in the Organization Dr. Taysir Hassan Abdel Hamid IS Department Faculty of Computer and Information Assiut University March 8,
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:
Chapter 9: Logical Database Design and the Relational Model (ERD Mapping)
CS 405G: Introduction to Database Systems Lecture 2 : Database Design I.
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.
Data modeling using the entity-relationship model Chapter 3 Objectives How entities, tuples, attributes and relationships among entities are represented.
Slide Chapter 7 Relational Database Design by ER- to-Relational Mapping.
Mapping from conceptual model (EER-M)
Logical Design database design. Dr. Mohamed Osman Hegaz2 Conceptual Database Designing –Provides concepts that are close to the way many users perceive.
Databases Illuminated Chapter 3 The Entity Relationship Model.
Chapter 9 Logical Database Design : Mapping ER Model To Tables.
Entity-Relationship Model Chapter 3 II COSC 457 Sungchul Hong.
Data Modeling Using the Entity-Relationship (ER) Data Model (Based on Chapter 3 in Fundamentals of Database Systems by Elmasri and Navathe, Ed. 3)
Chapter 17 Logical Database Design for the Relational Model Pearson Education © 2009.
DatabaseIM ISU1 Chapter 7 ER- and EER-to-Relational Mapping Fundamentals of Database Systems.
Data Modeling Using the Entity- Relationship (ER) Model.
Chapter 3: Data Modeling Using the Entity-Relationship (ER) Data Model
Lecture4: Informal guidelines for good relational design Mapping ERD to Relation Prepared by L. Nouf Almujally Ref. Chapter3 Lecture4 1.
1 © Prentice Hall, 2002 ITD1312 Database Principles Chapter 4B: Logical Design for Relational Systems -- Transforming ER Diagrams into Relations Modern.
Database Design Slide 1 Database Design Lecture 7 part 2 Mapping ERD to Tables.
ER- Relational Mapping (Based on Chapter 9 in Fundamentals of Database Systems by Elmasri and Navathe, Ed. 3)
© 2009 Pearson Education, Inc. Publishing as Prentice Hall 1 Chapter 5 (Part a): Logical Database Design and the Relational Model Modern Database Management.
CSE 412/598 DATABASE MANAGEMENT COURSE NOTES 3. ENTITY-RELATIONSHIP CONCEPTUAL MODELING Department of Computer Science & Engineering Arizona State University.
Mapping ER Diagrams to Tables
Copyright © 2016 Pearson Education, Inc. Modern Database Management 12 th Edition Jeff Hoffer, Ramesh Venkataraman, Heikki Topi CHAPTER 2: MODELING DATA.
Relational Database Design by ER- and EER-to-Relational Mapping
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.
Data Modeling Using the Entity- Relationship (ER) Model
Comp 1100 Entity-Relationship (ER) Model
Entity- Relationship (ER) Model
Chapter 4: Part B Logical Database Design and the Relational Model
Chapter -3- Data Modeling Using the Entity-Relationship Model
Relational Database Design by ER- and EERR-to-Relational Mapping
Relational Database Design by ER-to-Relational Mapping
Chapter (9) ER and EER-to-Relational Mapping, and other Relational Languages Objectives How a relational database schema can be created from a conceptual.
Chapter (9) ER and EER-to-Relational Mapping, and other Relational Languages Objectives How a relational database schema can be created from a conceptual.
بسم الله الرحمن الرحيم.
Relational Database Design by ER- and EER-to-Relational Mapping
Conceptual Data Modeling Using Entities & Relationships
Mapping an ERD to a Relational Database
Entity Relation Model Tingting Zhang.
Chapter (7) ER-to-Relational Mapping, and other Relational Languages
Mapping an ERD to a Relational Database
Relational Database Design by ER-to-Relational Mapping
Presentation transcript:

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 entity types 2)Rule for relationships 3)Rule for attributes 4)Rule for generalization/specialization hierarchies (will not be discussed in this course) 5)Rule for participation constraint

1.Entities Each entity set is implemented with a separate relation. a.Strong Entities Strong, or regular, entities are mapped to their own relation. The PK (Primary Key) is chosen from the set of keys available.

A Example: Strong Entities A c d e cde

1.Entities Each entity set is implemented with a separate relation. b.Weak Entities Weak entities are mapped to their own relation The PK of the weak entity is the combination of the PKs of entities related through identifying relationships and the discriminator (partial key) of the weak entity.

B Example: Weak Entities A c d e cxy B x y

2.Relationships We’ll consider binary relationships only All relationships involve the use of foreign keys: the PK attribute of one entity set is added as an attribute to the relation representing the other entity set a. Binary One-To-One In general, with a one-to-one relationship, you have a choice regarding where to implement the relationship. You may choose to place a foreign key in one of the two relations, or in both.

B 1 1 Example: 1-1 A c d e xyc B x y c is a FK in B

A 1 1 Example: 1-1 A c d e c…X B x y X is a FK in A

A 1 1 If the participation constraint on an entity set is mandatory, we must choose the table for that entity set. A c d e c…X B x y X is a FK in B

2.Relationships b.Binary One-To-Many With a one-to-many relationship you must place a foreign key in the relation corresponding to the many side of the relationship.

Example: 1-n A c d e xyc B B x y 1 n c is a FK placed on the “many” side of the relationship

Example: 1-n A c d e xy B c B x y 1 n s is also involved in the table s s

2.Relationships c.Binary Many-To-Many A many-to-many relationship must be implemented with a separate relation for the relationship. This new relation will have a composite primary key comprising the primary keys of the participating entity sets plus any discriminator attribute.

Example: m-n A c d e xcs AB B x y m n x and c are FKs, and together they form the PK of AB s

3.Attributes All attributes, with the exception of derived and composite attributes, must appear in relations. a.Simple, atomic These are included in the relation created for the pertinent entity set, many-to-many relationship, or n-ary relationship.

A Example: Atomic Attributes A c d e cde

3.Attributes b.Multi-valued Each multi-valued attribute is implemented using a new relation. This relation will include the primary key of the original entity set. The primary key of the new relation will be the primary key of the original entity set and the multi-valued attribute. Note that in this new relation, the attribute is no longer multi-valued.

Example: Multi-valued Attributes A c d e cd A ce AE e is a multi-valued attribute.

3.Attributes c.Composite Composite attributes are not included. However the atomic attributes comprising the composite attribute must appear in the pertinent relation.

Example: Composite Attributes c d e cde A A n

4.Generalization/Specialization Hierarchies can ignore this section

5. Participation constraints If a relationship is mandatory for an entity set, then if the entity set is on the “many” side of the relationship, then a specification is required to ensure a foreign key has a value, and that it cannot be null setting the ‘required’ property for the FK in MS Access ( should know how to do this), or NOT NULL constraint in the DDL. N A c d B x y 1

cd A xyc B The “required” property for attribute c is set “yes”.

Setting the required property to Yes

5. Participation constraints Otherwise, if the entity set is on the “one” side of a relationship, then a check constraint or database trigger can be specified to ensure compliance. N A c d B x y 1

cd A xyc B A program should be produced to check that any value appearing in c-column in table A must appear at least once in c-column in table B.

Example The company database keeps track of a company’s employees, departments, and projects: Requirements: concerning the department: 1.company is organized into departments 2.a department has a unique name, a unique number, and a specific employee is its’ manager 3.we track the start date for the manager function 4.a department may be in several locations 5.a department controls a number of projects concerning the project: 6.a project has a unique name, a unique number, and is in a single location

example continued concerning the employee: 7.each employee has a name, social insurance number, address, salary, sex, and birth date 8.an employee is assigned to one department but may work on several projects which are not necessarily controlled by the same department 9.we track the number of hours per week that an employee works on each project 10.we keep track of the direct supervisor of each employee 11.we track the dependents of each employee (for insurance purposes) concerning the dependent: 12.we record each dependent’s first name, sex, birth date, and relationship to the employee

The entities: employee department project dependent

The entities: bdate ssn name lname minit fname sex address salary birthdatenamesex relationship name numberlocation name numberlocation employee department project dependent

With relationships: employee department project dependent works for manages works on dependents of controls supervision 1 N N 1 NM 1 N 1 1 N 1 supervisor supervisee partial constraint total constraint

employee department project dependent works for manages works on dependents of controls supervision bdate ssn name lname minit fname sex address salary birthdatenamesex relationship name numberlocation name number number of employees startdate hours N supervisor supervisee M N 1 1 N N degree location

Summary 1.Entities a. Each entity set is implemented with a separate relation. b.Weak Entities Weak entities are mapped to their own relation The PK of the weak entity is the combination of the PKs of entities related through identifying relationships and the discriminator (partial key) of the weak entity;

2.All relationships involve foreign keys. If the relationship is identifying then the primary key of the strong entity must be propagated to the relation representing the weak entity. a.Binary One-To-One In general, with a one-to-one relationship, you have a choice regarding where to implement the relationship. You may choose to place a foreign key in one of the two relations, or in both. b.Binary One-To-Many With a one-to-many relationship you must place the foreign key in the relation corresponding to the many side of the relationship.

c.Binary Many-To-Many A many-to-many relationship must be implemented with a separate relation for the relationship. This new relation will have a composite primary key comprising the primary keys of the participating entity sets plus any discriminator attribute. d.n-ary, n>2 new relation is generated for the n-ary relationship. This new relation will have a composite primary key comprising the primary keys of the participating entity sets plus any discriminator attribute. If the cardinality related for any entity set is 1, then the primary key of that entity set is only included as a foreign key and not as part of the primary key of the new relation.

3.Attributes a. Simple, atomic These are included in the relation created for the pertinent entity set, many-to-many relationship, or n-ary relationship. b. Multi-Valued A multi-valued attribute is implemented using a new relation. This relation will include the primary key of the entity set. The primary key of the new relation will be the primary key of the entity set and the multi-valued attribute. Note that in this relation, the attribute is no longer multi-valued. c. Composite Composite attributes must be replaced by their equivalent atomic attributes in the pertinent relation.

4.Generalization/Specialization Hierarchies There are several options available for this case … (ignore for ) 5.Participation constraints. If a relationship is mandatory for an entity set, then if the entity set is on the “many” side of the relationship, a specification is required (a NOT NULL constraint) to ensure a foreign key has a value, and that it cannot be null. If the entity set is on the “one” side of a relationship, then that “one” side will be chosen as the primary table and the other is chosen as the referenced table. A NOT NULL constraint for the foreign key should be specified.