MIS 3053 Database Design & Applications The University of Tulsa Professor: Akhilesh Bajaj ER Model Lecture 4 Mapping an ER model to tables © Akhilesh Bajaj,

Slides:



Advertisements
Similar presentations
Chapter 2: Entity-Relationship Model
Advertisements

Convert ER to Relational Database Entity relation Entity relation Attributes attributes Attributes attributes Primary key primary key Primary key primary.
Temple University – CIS Dept. CIS616– Principles of Database Systems
Relational Database Design Via ER Modelling
Chapter 2: Entity-Relationship Model
Enhanced Entity-Relationship Modeling. Strong and Weak Entity Types Strong entity: Each object is uniquely identifiable using primary key of that entity.
Text-Book Chapters (7 and 8) Entity-Relationship Model
1 Class Number – CS 304 Class Name - DBMS Instructor – Sanjay Madria Instructor – Sanjay Madria Lesson Title – EER Model –21th June.
©Silberschatz, Korth and Sudarshan2.1Database System Concepts Chapter 2: Entity-Relationship Model Entity Sets Relationship Sets Design Issues Mapping.
Database Design & Mapping
Modeling Data The Entity Relationship Model (ER) For Database Design.
Entity-Relationship Model and Diagrams (continued)
Information Resources Management February 13, 2001.
©Silberschatz, Korth and Sudarshan2.1Database System Concepts Reduction of an E-R Schema to Tables A database which conforms to an E-R diagram can be represented.
Entity-Relationship Model
Mapping ERM to relational database
Ch 6: ER to Relational Mapping
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.
Dr. Mohamed Osman Hegaz1 Conceptual data base design: The conceptual models: The Entity Relationship Model.
Database System Concepts, 5th Ed. Chapter 6: Entity-Relationship Model.
Chapter 5 Entity–Relationship Modeling
ER to Relational Translation COMSATS INSTITUTE OF INFORMATION TECHNOLOGY, VEHARI.
Chapter 3: Relational Model I Structure of Relational Databases Structure of Relational Databases Convert a ER Design to a Relational Database Convert.
Chapter 3: Relational Model  Structure of Relational Databases  Normal forms (chap. 7)  Reduction of an E-R Schema to Relational (Sect. 2.9)  Relational.
Chapter 7 Database Design and The E–R Model. 2 Goals n Facilitate DB design and represent the overall logical structure of the DB. n Definition Entities.
Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan Chapter 6: Entity-Relationship Model.
EXAMPLE. Subclasses and Superclasses Entity type may have sub-grouping that need to be represented explicitly. –Example: Employee may grouped into.
1 Session 2 Welcome: The seventh learning sequence “ Reduction of an EER schema to tables“ Recap : In the previous learning sequence, we discussed the.
MIS 7003 MIS Core Course The MBA Program The University of Tulsa Professor: Akhilesh Bajaj Introduction to Database Design All Slides in this presentation.
CS 370 Database Systems Lecture 9 The Relational model.
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.
Chapter 2 : Entity-Relationship Model Entity Sets Relationship Sets Design Issues Mapping Constraints Keys E-R Diagram Extended E-R Features Design of.
3 & 4 1 Database Systems: Design, Implementation, & Management, 7 th Edition, Rob & Coronel Keys Consists of one or more attributes that determine other.
SE305 Database System Technology 23/10/2014 Quiz-2.
ICOM 5016 – Introduction to Database Systems Lecture 9 Dr. Manuel Rodriguez Department of Electrical and Computer Engineering University of Puerto Rico,
Entity Relationship Diagram (2)
UNIT_2 1 DATABASE MANAGEMENT SYSTEM[DBMS] [Unit: 2] Prepared By Lavlesh Pandit SPCE MCA, Visnagar.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan Lecture-03 Introduction –Data Models Lectured by, Jesmin Akhter.
ICOM 5016 – Introduction to Database Systems Lecture 5 Dr. Manuel Rodriguez Department of Electrical and Computer Engineering University of Puerto Rico,
Software School of Hunan University Database Systems Design Part III : Mapping ER Diagram to Relational Schema.
Keys for Relationship Sets The combination of primary keys of the participating entity sets forms a super key of a relationship set. – (customer-id, account-number)
Entity-Relation Model. E-R Model The Entity-Relationship (ER) model was originally proposed by Peter in 1976 ER model is a conceptual data model that.
Data Modeling Using the Entity-Relationship (ER) Data Model.
MIS 3053 Database Design & Applications The University of Tulsa Professor: Akhilesh Bajaj ER Model Lecture 2 © Akhilesh Bajaj, 2000, 2002, 2003, 2004,
1 © Prentice Hall, 2002 ITD1312 Database Principles Chapter 4B: Logical Design for Relational Systems -- Transforming ER Diagrams into Relations Modern.
©Silberschatz, Korth and Sudarshan2.1Database System Concepts Chapter 2: Entity-Relationship Model Entity Sets Relationship Sets Design Issues Mapping.
CS157A Lecture 4 ER Model 2 Prof. Sin-Min Lee Department of Computer Science San Jose State University.
Database Design Slide 1 Database Design Lecture 7 part 2 Mapping ERD to Tables.
© 2009 Pearson Education, Inc. Publishing as Prentice Hall 1 Chapter 5 (Part a): Logical Database Design and the Relational Model Modern Database Management.
MIS3053 Database Design And Applications The University Of Tulsa Professor: Akhilesh Bajaj Normal Forms Lecture 2 © Akhilesh Bajaj, 2000, 2002, 2003,2004.
©Silberschatz, Korth and Sudarshan2.1Database System Concepts Chapter 2: Entity-Relationship Model Entity Sets Relationship Sets Mapping Constraints Keys.
©Silberschatz, Korth and Sudarshan7.1Database System Concepts - 6 th Edition Chapter 7: Entity-Relationship Model.
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.
Lecture 26 Enterprise Systems Development ( CSC447 ) COMSATS Islamabad Muhammad Usman, Assistant Professor.
MIS 3053 Database Design & Applications The University of Tulsa Professor: Akhilesh Bajaj ER Model Lecture 3 © Akhilesh Bajaj, 2000, 2002, All Rights.
Chapter 2: Entity-Relationship Model
Entity-Relationship Model
Chapter 2: Entity-Relationship Model
Entity-Relationship Model
Chapter 2: Entity-Relationship Model
Introduction to Database
Session 2 Welcome: The seventh learning sequence
CHAPTER 4: LOGICAL DATABASE DESIGN AND THE RELATIONAL MODEL
Chapter 6: Entity-Relationship Model
The University of Tulsa Professor: Akhilesh Bajaj
Database EER.
Entity Relation Model Tingting Zhang.
Chapter 2: Entity-Relationship Model
Presentation transcript:

MIS 3053 Database Design & Applications The University of Tulsa Professor: Akhilesh Bajaj ER Model Lecture 4 Mapping an ER model to tables © Akhilesh Bajaj, 2000, 2002, 2003, All Rights Reserved.

Review of the ER Model So Far Entities and entity sets Relationships and relationship sets Attributes of entity sets and relationship sets Degree of relationship sets Cardinality of relationship sets Keys of entity sets Existence dependencies (weak entity sets) Subclass / Superclass hierarchy amongst entity sets

Goals Today Learn how to map an ER diagram to a set of tables In-class assignment on mapping ER diagrams to tables. Goal of ER module: End-user descriptions One ER diagram Set of tables

A table has a name A table has columns - the columns are also called attributes. The data in the table is stored as rows. A table has a primary key (determines each row uniquely). A database consists of many such tables, and is called a relational schema. What is a Table

Create a separate table for the strong entity set. The name of the table is the name of the entity set. The columns of the table are the attributes of the strong entity set. The primary key of the table is the primary key of the entity set. Mapping Strong Entity Sets

Create a separate table for the weak entity set. The name of the table is the name of the entity set. The columns of the table are the attributes of the weak entity set + the primary key of the corresponding strong entity set. The primary key of the table is the primary key of the corresponding strong entity set + the unique identifier of the weak entity set. Mapping Weak Entity Sets

Create a separate table for the superclass first, using the rules for mapping entity sets we have seen earlier. For each subclass entity set, create a separate table. The columns of each table = the additional attributes of the corresponding subclass entity set + the primary key of the superclass entity set. The primary key of the subclass table is the primary key taken from the superclass table. Recall that the hierarchy triangle is NOT a relationship set and is not mapped into a table. Mapping Superclass / Subclass Hierarchies

Create a separate table for the multivalued attribute. The name of the table is the name of the attribute. The columns of the table are the primary key of the entity set to which the attribute belongs + a separate column for values of the attribute. The primary key of the table is all the columns of the table. If there are separate multivalued attributes, then create a separate table for EACH attribute. Mapping Multivalued Attributes

Only attributes that are the leaves of a composite hierarchy are mapped as columns of a table. If the composite attribute is single-valued, treat the leaf attributes as ordinary attributes, when mapping them. If the composite attribute is multivalued, treat the leaf attributes as multivalued-attributes, when mapping them, except create only ONE new table with all the leaf attributes in it. The Primary Key of this table will be all the attributes of the table. Note: There can never be a case where only some leaf attributes are multivalued and others are not. Either the entire composite Attribute (such as address) is multivalued, or it is not. Mapping Composite Attributes

1. Mapping Existence Relationship sets (Weak entity set relationship set with its strong entity set: DOUBLE Diamond) : Existence relationship sets (between weak and corresponding strong entity sets) are NOT mapped into tables.These are the ones that are represented by double diamonds. We should note that a weak entity set can have other, normal relationship sets with other entity sets also. These are treated as normal (single diamond) relationship sets, when mapping. Let’s see how to map normal relationship sets to tables next. Mapping Relationship Sets

2. MAPPING A RELATIONSHIP SET (SINGLE DIAMOND) 2 a) Binary relationships that are 0/1:1..…◊..... Any cardinality : Add a column(s) in the table that corresponds to the entity set that is on the “Any Cardinality” side. Example: Mapping Relationship Sets AB R 0:10:n “Any Cardinality here” Side The column(s) we add to B here is the primary key of the entity set that is on the 0/1:1 side (A in this case) and any other attributes of the relationship set. So, we borrow the primary key of A into B, but it does NOT become part of the primary key of B. It’s still a foreign key referring A though. We can also preface the columns added to B with the label of R, to show that the columns are borrowed because of R. [Nota Bene: If the cardinality is 0:1, null values have to be allowed, if it is 1:1, then null values should not be allowed, for the primary key of A when put in B.] 0/1:1 here Side

2 b). Binary relationship sets with cardinality NOT as in 2a) AND all ternary & higher degree relationship sets: Create a separate table with the same name as the name of the relationship set The columns of the table are the attributes of the relationship set (if any) + primary keys of all the entity sets that participate in the relationship set. The primary key of the table is = the primary keys of all the entity sets that participate in the relationship set. If any of the entity sets in the relationship set are weak, recall that the primary key of a weak entity set is the unique identifier + the primary key of the corresponding strong entity set. Mapping Relationship Sets Note: Rules 1 & 2 are mutually exclusive: Rule 1 is for double diamonds, rule 2 is for single diamonds

Given an ER diagram, what sequence of steps should we follow? Map the strong entity sets Map the weak entity sets Map the subclass entity sets Map multivalued attributes, if any Map Composite attributes, if any Map relationship sets Sequence Of Steps

The examples are deliberately abstract, to emphasize the steps, independent of any particular situation. Example 1 AB Attrib A1 Attrib D2 Attrib R11 Attrib B1 Attrib B2 Attrib A2 Attrib D1 Attrib R21 Attrib C1 Attrib C2 Attrib C3 C R1 R2 0:11:m 1:n D 0:1 1:n

The examples are deliberately abstract, to emphasize the steps, independent of any particular situation. Example 2 B Attrib D2 Attrib B1 Attrib B2 Attrib D1 Attrib R11 R1 0:m D A Attrib A1 Attrib A2 1:1 0:m 1:n

In Class Assignment 1 Al’s motor shop (AMS) is an automobile repair facility owned by the Capone family. AMS has 5 repair bays. Each repair bay (place where car is repaired) has a bay_id and bay_location. AMS employs 14 employees. Each employee has an employee_id, address, phone and salary. Of these 14, 2 are office staff. They are further described by typing_speed and degree_held. The 12 mechanics are further described by tech_level. Each mechanic is assigned to work on one bay. AMS customers have a cust_id, name, address, phone. In addition, Mr. Capone also wants to capture information for each customer that lists the mechanic who last did a job for the customer, the date on which the job was done, and the amount the customer paid to AMS. The above requirements have been captured in an ER diagram. Please map the ER diagram to tables.

In Class Assignment Repair_bays Mechanics Employees Customers Office_staff Emp_id Degree_held Typing_speedTech_level Cust_id name phone Bay_id Bay_loc address phone Salary address 0:n1:1 0:1 0:n Works Last_job IS A date payment User-defined, disjoint, total

Tables Mapped from the ER Diagram Employees (emp_id, phone, address, salary) Mechanics (emp_id, tech_level, bay_id) emp_id FK REF employees, bay_id FK REF bays Office_staff (emp_id, typing_speed, degree_held) emp_id FK REF employees Repair_bays (bay_id, bay_loc) Customers (cust_id, name, address, phone, last_job_emp_id, last_job_date, last_job_payment)l last_job_emp_id FK refs mechanics