C ONVERTING ERD S TO R ELATIONAL T ABLES Joe Meehean 1.

Slides:



Advertisements
Similar presentations
ER to Relational Mapping. Logical DB Design: ER to Relational Entity sets to tables. CREATE TABLE Employees (ssn CHAR (11), name CHAR (20), lot INTEGER,
Advertisements

Convert ER to Relational Database Entity relation Entity relation Attributes attributes Attributes attributes Primary key primary key Primary key primary.
Designing tables from a data model (Chapter 6) One base table for each entity.
R ELATIONAL M ODEL TO SQL Data Model. 22 C ONCEPTUAL D ESIGN : ER TO R ELATIONAL TO SQL How to represent Entity sets, Relationship sets, Attributes, Key.
Relational Database. Relational database: a set of relations Relation: made up of 2 parts: − Schema : specifies the name of relations, plus name and type.
Enhanced Entity-Relationship Modeling. Strong and Weak Entity Types Strong entity: Each object is uniquely identifiable using primary key of that entity.
E NTITY R ELATIONSHIP D IAGRAMS Joe Meehean 1. E NTITY R ELATIONSHIP M ODEL Entity type an object (noun) e.g., student attributes (e.g., last name) Relationship.
Entity Relationship (ER) Modeling
SQL Lecture 10 Inst: Haya Sammaneh. Example Instance of Students Relation  Cardinality = 3, degree = 5, all rows distinct.
D EVELOPING D ATA M ODELS Joe Meehean 1. B USINESS R EQUIREMENTS Business Narrative How the company works, what do they do Consistency and Simplicity.
4 4 Chapter 4 Entity Relationship (E-R) Modeling Database Systems: Design, Implementation, and Management 4th Edition Peter Rob & Carlos Coronel.
Entity Relationship (ER) Modeling
4 1 Chapter 4 Entity Relationship (ER) Modeling Database Systems: Design, Implementation, and Management, Sixth Edition, Rob and Coronel.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 4 Entity Relationship (ER) Modeling.
Entity Relationship (ER) Modeling
Entity Relationship (ER) Modeling
Copyright © 2015 Pearson Education, Inc. Database Design Chapters 17 and
Agenda for Week 1/31 & 2/2 Learn about database design
McGraw-Hill/Irwin Copyright © 2007 by The McGraw-Hill Companies, Inc. All rights reserved. Chapter 6 Developing Data Models for Business Databases.
Chapter 4 Entity Relationship (ER) Modeling
Database Systems: Design, Implementation, and Management Tenth Edition
Chapter 6 Developing Data Models for Business Databases.
CSCI 242 Relational Data Modeling Copyright 2011, David C. Roberts, all rights reserved.
CSCI 6442 Entity-Relation Data Modeling Copyright 2012, David C. Roberts, all rights reserved.
Mapping ERM to relational database
Chapter 5 1 © Prentice Hall, 2002 Chapter 5: Transforming EER Diagrams into Relations Mapping Regular Entities to Relations 1. Simple attributes: E-R attributes.
1. 2 Data Modeling 3 Process of creating a logical representation of the structure of the database The most important task in database development E-R.
ER to Relational Mapping. Logical DB Design: ER to Relational Entity sets to tables. CREATE TABLE Employees (ssn CHAR (11), name CHAR (20), lot INTEGER,
Developing Data Models for Business Databases (Part II)
DATA MODELING AND DATABASE DESIGN
Chapter 5 Entity Relationship (ER) Modelling
4 1 Chapter 4 Entity Relationship (ER) Modeling Database Systems: Design, Implementation, and Management, Sixth Edition, Rob and Coronel.
MIS 301 Information Systems in Organizations Dave Salisbury ( )
MIS 301 Information Systems in Organizations Dave Salisbury ( )
R ELATIONAL D ATA M ODEL Joe Meehean 1. R ELATIONAL D ATA M ODEL Data stored as a set of relations really just tables Tables related to one another through.
Normalization (Codd, 1972) Practical Information For Real World Database Design.
Domain Modeling Part1: Entity Relationship Diagram Chapter 4 pp part 1 1.
1 Relational Databases and SQL. Learning Objectives Understand techniques to model complex accounting phenomena in an E-R diagram Develop E-R diagrams.
Database Design, Application Development, and Administration, 5 th Edition Copyright © 2011 by Michael V. Mannino All rights reserved. Chapter 6 Developing.
Database Systems: Design, Implementation, and Management Tenth Edition Chapter 4 Entity Relationship (ER) Modeling.
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 
The Relational Model1 ER-to-Relational Mapping and Views.
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.
Data modeling using the entity-relationship model Chapter 3 Objectives How entities, tuples, attributes and relationships among entities are represented.
Database Systems: Design, Implementation, and Management Ninth Edition Chapter 4 Entity Relationship (ER) Modeling.
Relational Theory and Design
Constraints cis 407 Types of Constraints & Naming Key Constraints Unique Constraints Check Constraints Default Constraints Misc Rules and Defaults Triggers.
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 4 ENTITY RELATIONSHIP (ER) MODELING Instructor Ms. Arwa Binsaleh 1.
Lecture 3 Book Chapter 3 (part 2 ) From ER to Relational.
Database Design – Lecture 6 Moving to a Logical Model.
Chapter 3: Modeling Data in the Organization. Business Rules Statements that define or constrain some aspect of the business Assert business structure.
Howard Paul. Sequential Access Index Files and Data File Random Access.
DATA MODELING AND DATABASE DESIGN DATA MODELING AND DATABASE DESIGN Part 2.
Database Design, Application Development, and Administration, 6 th Edition Copyright © 2015 by Michael V. Mannino. All rights reserved. Chapter 5 Understanding.
Database Design Chapters 17 and 18.
Let try to identify the conectivity of these entity relationship
Logical DB Design: ER to Relational
Tables and Their Characteristics
Developing Data Models – Conversion Rules
Database Systems Instructor Name: Lecture-12.
Session 2 Welcome: The seventh learning sequence
CHAPTER 4: LOGICAL DATABASE DESIGN AND THE RELATIONAL MODEL
Database Systems Instructor Name: Lecture-9.
Chengyu Sun California State University, Los Angeles
Mapping an ERD to a Relational Database
Database Management system
Database Management system
Entity Relationship (ER) Modeling
Presentation transcript:

C ONVERTING ERD S TO R ELATIONAL T ABLES Joe Meehean 1

T HE P LAYERS ERDs easy to reason about express lots of information in limited space easy to create from business narrative Relational Tables easy for DBMSs to store data in tables use SQL to ask lots of different questions about data Need to convert ERDs to Relational tables using a set of rules and some intuition 2

E NTITY T YPE R ULE each entity becomes a table primary key of entity is primary key of table attributes become columns 3 Student Student ID Last name First name Student IDLast NameFirst Name

1-M R ELATIONSHIP R ULE primary key of parent becomes a foreign key in table of child entity child entity is entity near Crow’s Foot symbol if minimum cardinality on parent side is 1 (required), foreign key cannot accept null value 4

Teaches 1-M R ELATIONSHIP R ULE 5 Faculty Faculty ID Last name First name Offering Section # Room Time Section #RoomTime Offering

Enrolls M-N R ELATIONSHIP R ULE M-N relationship becomes it own table primary key is combined key formed from primary keys of participating entities 6 Offering Section # Room Time Student Student ID Last name First name Enrolls Student IDSection #

I DENTIFICATION D EPENDENCY R ULE add a component to the primary key of the weak entity primary key = primary key of weak entity (if any) + primary keys from independent entities 7

I DENTIFICATION D EPENDENCY R ULE 8 Has Course Number Name Credits Offering Section # Room Time NumberSection #RoomTimeFaculty ID Offering

Q UESTIONS ? 9

Has- Empl Has In 10 Parts Part# Description Quantity Distributor Customer# Name Address Motorcycle ID# Quantity Style Has- JobTitle Order Order# Date $Total Supplier Supplier# Name Address Employee Employee# Name Years Has Years JobTitle Position# Name BaseSalary Supplies In

O PTIONAL 1-M R ELATIONSHIPS R ULE Optional relationship: minimal cardinality of 0 on parent side (1-side) Convert using the 1-M rule foreign key in child table (M-side) foreign key can be NULL can be problem for queries 11

O PTIONAL 1-M R ELATIONSHIPS R ULE 12 Teaches 12 Faculty Faculty ID Last name First name Offering Section # Room Time Section #RoomTimeFaculty ID A4511NULL B6812Blem C581Daniels D352Blem Offering

O PTIONAL 1-M R ELATIONSHIPS R ULE Optionally, can use Optional 1-M Relationship Rule relationship becomes its own table primary keys in both entities become foreign keys primary key from child entity (M-side) becomes primary key in new table 13

O PTIONAL 1-M R ELATIONSHIPS R ULE 14 Teaches 14 Faculty Faculty ID Last name First name Offering Section # Room Time Faculty ID BBlem CDaniels DBlem Teaches Section #RoomTime A4511 B6812 C581 D352 Offering

O PTIONAL 1-M R ELATIONSHIPS R ULE When to used Optional 1-M Relationship Rule its optional Optional rule makes more tables more complex more SQL operations (slower) 1-M rule makes NULL foreign keys can be difficult to deal with 3 rd option replace optional relationship with required relationship and default value 15

O PTIONAL 1-M R ELATIONSHIPS R ULE 16 Teaches 16 Faculty Faculty ID Last name First name Offering Section # Room Time Section #RoomTimeFaculty ID A4511Faculty B6812Blem C581Daniels D352Blem Offering

G ENERALIZATION H IERARCHY R ULE Each entity in a generalization hierarchy becomes a table Includes only attributes in entity not its ancestors Except it includes ancestors primary key uses it as its own primary key also a foreign key Perform cascading deletes if ancestor is deleted so is subtype table entry 17

G ENERALIZATION H IERARCHY R ULE 18 Student Major Grad Date Faculty Department Office College People College ID Last name First name College ID Last Name First Name College ID Depart- ment Office College People Faculty

1-1 R ELATIONSHIP R ULE Put a foreign key in each table in the relationship Unless one table will have many NULL foreign keys Then drop the foreign key in the table where it will be mostly NULL 19

1-1 R ELATIONSHIP R ULE 20 Faculty Faculty ID Last name First name Department Dept. Name Funding Chairs 20 Faculty ID Last Name First Name Dept Name Fund -ing FacultyDepartment

1-1 R ELATIONSHIP R ULE 21 Faculty Faculty ID Last name First name Department Dept. Name Funding Chairs 21 Faculty ID Last Name First Name Dept Name Fund- ing Faculty Department

S ELF R EFERENCING E NTITIES Apply same rules 1-M rule add a new column with primary key as foreign key M-N rule add a new table representing the relationship 22

S ELF R EFERENCING E NTITIES 23 Employee Employee ID Last name First name Manages Employee ID Last NameFirst NameSupervisor Employee

Prerequisite S ELF R EFERENCING E NTITIES 24 Course Number Name Credits NumberNameCredits Course Prerequisites

C ONVERTING ERD R EVIEW Every entity becomes a table Some relationships become tables Majority of conversion rules dictate where foreign key goes foreign key links row in table to primary key in another table M-N: new table with foreign keys from both entities 1-M: foreign key in M entity optional 1-M: more complex 25

Q UESTIONS ? 26

27 Faculty Faculty ID Last name First name Student Student ID Last name First name Major Advisor Convert to tables

28 Convert to tables Hourly Hours Rate Salary Contract Expires Employee Employee ID Last name First name

29 Convert to tables In Building Building ID Name Address Room Room # Capacity

30 Convert to tables Married Faculty Faculty ID First Name Last Name