More on E-R Diagrams After this lecture, you should be able to:

Slides:



Advertisements
Similar presentations
Banking Business Scenario
Advertisements

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,
Relational Database Design Via ER Modelling
Entity-Relationship (ER) Modeling
Database Management Systems, R. Ramakrishnan and J. Gehrke1 The Entity-Relationship Model Chapter 2.
Conceptual Data Modeling: ER
Entity-Relationship Model
1 Class Number – CS 304 Class Name - DBMS Instructor – Sanjay Madria Instructor – Sanjay Madria Lesson Title – EER Model –21th June.
MIS 210 Fall 2004Sylnovie Merchant, Ph. D. Lecture 4: Data Modeling Process Modeling MIS 210 Information Systems I.
SLIDE 1IS Fall 2002 Database Management: Discussion Session University of California, Berkeley School of Information Management and.
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 5-1 David M. Kroenke’s Chapter Five: Data Modeling with the Entity-Relationship.
ENTITY RELATIONSHIP DATA MODEL ELIZABETH GEORGE. INTRODUCTION Architect Aeronautical engineers Computer architects Traffic engineers.
CHAPTER 2: MODELING DATA IN THE ORGANIZATION © 2013 Pearson Education, Inc. Publishing as Prentice Hall 1 Modern Database Management 11 th Edition Jeffrey.
Class Number – CS 304 Class Name - DBMS Instructor – Sanjay Madria Instructor – Sanjay Madria Lesson Title – ER Model.
Michael F. Price College of Business Chapter 6: Logical database design and the relational model.
Entity Relationship Model Chapter 6. Basic Elements of E-R Model Entity Object of the real world that stores data. Eg. Customer, State, Project, Supplier,
 Keys are special fields that serve two main purposes: ◦ Primary keys are unique identifiers of the relation in question. Examples include employee numbers,
The Entity-Relationship Model. 421B: Database Systems - ER Model 2 Overview of Database Design q Conceptual Design -- A first model of the real world.
Ch5: ER Diagrams - Part 2 Much of the material presented in these slides was developed by Dr. Ramon Lawrence at the University of Iowa.
© 2007 by Prentice Hall (Hoffer, Prescott & McFadden) 1 Entity Relationship Diagrams (ERDs)
3.1 CSIS 3310 Chapter 3 The Entity-Relationship Model Conceptual Data Modeling.
Chapter 4 The Relational Model.
IS 325 Notes for Wednesday September 18, 2013.
MIS 385/MBA 664 Systems Implementation with DBMS/ Database Management Dave Salisbury ( )
Module Title? Data Base Design 30/6/2007 Entity Relationship Diagrams (ERDs)
MIS 301 Information Systems in Organizations Dave Salisbury ( )
MIS 301 Information Systems in Organizations Dave Salisbury ( )
Component 4: Introduction to Information and Computer Science Unit 6: Databases and SQL Lecture 2 This material was developed by Oregon Health & Science.
©Silberschatz, Korth and Sudarshan2.1Database System Concepts Chapter 2: Entity-Relationship Model Entity Sets Relationship Sets Design Issues Mapping.
What we’ve learnt Doc 5.69 Doc 5.70 Section 1-3. A simple database Related objects Tables hold the data Forms, reports, queries to access the data.
1 Relational Databases and SQL. Learning Objectives Understand techniques to model complex accounting phenomena in an E-R diagram Develop E-R diagrams.
Data Modeling IST210 Class Lecture.
Entity-Relationship (ER) Modelling ER modelling - Identify entities - Identify relationships - Construct ER diagram - Collect attributes for entities &
Chapter 9: Logical Database Design and the Relational Model (ERD Mapping)
1 A Demo of Logical Database Design. 2 Aim of the demo To develop an understanding of the logical view of data and the importance of 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.
Component 4/Unit 6b Topic II Relational Databases Keys and relationships Data modeling Database acquisition Database Management System (DBMS) Database.
Database Management Systems MIT Lesson 02 – Database Design (Entity Relationship Diagram) By S. Sabraz Nawaz.
Normalization Exercise. First Normal Form Second Normal Form.
In this session, you will learn to: Map an ER diagram to a table Objectives.
Chapter 9 Logical Database Design : Mapping ER Model To Tables.
Data Modeling Using the Entity-Relationship (ER) Data Model (Based on Chapter 3 in Fundamentals of Database Systems by Elmasri and Navathe, Ed. 3)
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.
Data Modeling Using the Entity- Relationship (ER) Model.
Chapter 3: Modeling Data in the Organization. Business Rules Statements that define or constrain some aspect of the business Assert business structure.
1 © Prentice Hall, 2002 ITD1312 Database Principles Chapter 4B: Logical Design for Relational Systems -- Transforming ER Diagrams into Relations Modern.
David M. Kroenke and David J. Auer Database Processing Fundamentals, Design, and Implementation Chapter Five: Data Modeling with the Entity-Relationship.
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.
© 2009 Pearson Education, Inc. Publishing as Prentice Hall 1 Chapter 3: Modeling Data in the Organization Modern Database Management 9 th Edition Jeffrey.
Lecture 4: Logical Database Design and the Relational Model 1.
Lecture # 14 Chapter # 5 The Relational Data Model and Relational Database Constraints Database Systems.
IT 5433 LM3 Relational Data Model. Learning Objectives: List the 5 properties of relations List the properties of a candidate key, primary key and foreign.
Database Designsemester Slide 1 Database Design Lecture 7 Entity-relationship modeling Text , 7.1.
Contents Design Process Modeling Constraints E-R Diagram Design Issues
Databases (CS507) CHAPTER 7.
Relational Database Design by ER- and EER-to- Relational Mapping
Chapter 4: Logical Database Design and the Relational Model
Entity-Relationship Model
Tables and Their Characteristics
Entity – Relationship Model
The Entity-Relationship Model
CHAPTER 4: LOGICAL DATABASE DESIGN AND THE RELATIONAL MODEL
Data Modeling for Database Design 2
Database Systems Instructor Name: Lecture-9.
Lecture 9: The E/R Model II
Relational Database Design by ER- and EERR-to-Relational Mapping
Relational Database Design by ER- and EER-to-Relational Mapping
Database Management system
Entity-Relationship (E-R) Modeling
Presentation transcript:

More on E-R Diagrams After this lecture, you should be able to: Use E-R Model effectively to design a database for a mail order company. Know more features of ER Diagram: Weak Entity Converting a M:M Relationship Type into Two 1:M Relationship Types Ternary Relationship Type Build Extended ER digram to represent Entity Type Hierarchy (supertype-subtype relationship). Work on Assignment 4. 1

Mail-Order Company Database A small mail-order company must maintain the following information: The company must keep track of all its customers with their names, addresses, and the dates of their first orders. A unique customer number is assigned to each customer. Each order placed by a customer may contain multiple order-lines. Each order-line is used to order one kind of product for some quantity. The date of the order must be recorded. Each customer assigns order numbers to his/her orders. Orders from different customers may have identical order numbers. Each product has a product number, a product name, and a unit retail price.

Mail-Order Company Database (cont'd) Each product may have multiple suppliers. A unique supplier number is assigned to each supplier. Different suppliers may offer the same product at different wholesale prices. A supplier may supply multiple products. The names and addresses of the suppliers must be recorded. The company owns multiple warehouses. Each warehouse is identified by the name of the city where it is located. The telephone number of each warehouse must be recorded. The number of each product stocked at each warehouse must be recorded. A warehouse can stock different products. However, each product is stocked at most at one warehouse.

What Should an Entity Be? “An entity is an object in the real world that is distinguisable from other objects” SHOULD BE: An object that will have many instances in the database An object that will be composed of multiple attributes An object that we are trying to model SHOULD NOT BE: A user of the database system An output of the database system (e.g., a report)

Mail-Order Company Database: E-R Diagram address C# Customer name since 1 name place S# city telephone # address Supplier M O# Warehouse Order date M 1 M quantity quantity for store supply M M M wholeSalePrice Product name P# retailPrice

Weak Entities The keys of weak entities are unique only among their respective parents. Such keys are referred to as weak keys. In referring to a weak entity, we must use the combination of the weak key of the weak entity and the primary key of the parent entity. If the order numbers are assigned by customers, the order numbers are weak keys, and hence each order must be identified with (C#, O#). Weak entities can exist only when their parent entities exist.

Generating Relational Tables Provide a table for each entity type. The attributes of the entity type become the table columns. Provide a table for each M : M relationship type. The primary keys of the entity types associated by the relationship type become the foreign keys in the table. The combination of those foreign keys becomes the primary key of the table. Also, the attributes of the relationship type need be added to the table. A M:1 or 1:M relationship type does not require a new table. The primary key of the entity type on the 1-side can be added as a foreign key to the table representing the entity type on the M-side.

Mail-Order Company Database: E-R Diagram address C# Customer name since 1 name place S# city telephone # address Supplier M O# Warehouse Order date M 1 M quantity quantity for store supply M M M wholeSalePrice Product name P# retailPrice

Mail-Order Company Database: Relational Schema (1) Customer(C#, name, address, since) (2) Order(C#, O#, Date) (3) For(C#, O#, P#, quantity) (4) Product(P#, name, retailPrice, city, quantity) (5) Supplier(S#, name, address) (6) Supply(S#, P#, wholeSalePrice) (7) Warehouse(city, telephone#)

Converting a M:M Relationship Types into Two 1:M Relationship Types. Order O# date Order 1 date M quantity M quantity for Orderline Ol# M M Product 1 Product name P# retailPrice name P# retailPrice

Mail-Order Company Database: Relational Schema (1) Customer(C#, name, address, since) (2) Order(C#, O#, Date) (4) Orderline(Ol#, C#, O#, P#, quantity) (5) Product(P#, name, retailPrice, city, quantity) (6) Supplier(S#, name, address) (7) Supply(S#, P#, wholeSalePrice) (8) Warehouse(city, telephone#)

Ternary Relationship Type PJ# (key) Name Project S# (key) P# (key) supply Supplier Part Name City Price Name Weight

Table Created from a Ternary Relationship Type Table Supplier-Project-Part S# PJ# P# Price S1 PJ1 P1 10 P2 20 PJ2 12 S2 15 PJ3 22 S3 P3 30 3

Is This Equivalent to the One Ternary Relationship Type? supply Supplier Part participate use Project We cannot know which supplier supplied which part with respect to which project.

Convert Ternary To Binary Relationship Type PJ# (key) Name Project S# (key) P# (key) Supplier Shipment Part Name City Price Name Weight

(Entity) Type Hierarchy Indicated a supertype-subtype (superclass-subclass) relationship Is also called an IS-A hierarchy (or relationship) Example: A car is a vehicle A truck is a vehicle A dump truck is a truck A trailer-truck is a truck

(Entity) Type Hierarchy: Extended ER Schema license# owner Vehicle color nPassengers Car Truck weight style loadWeight DumpTruck TrailerTruck nTrailers

(Entity) Type Hierarchy: Vehicle Database For each vehicle, record its license number, owner, and color. For each car, record the number of passengers and style (sedan, convertible, etc.). For each truck, record the weight of the truck itself. For each dump truck, record the maximum weight of the load. For each trailer-truck, record the number of the trailers (1 - 3).

Relational Schema for Type Hierarchy I Store all the information on one entity in one table. Vehicle(license#, owner, color) Car(license#, owner, color, nPassengers, style) Truck(license#, owner, color, weight) DumpTruck(license#, owner, color, weight, loadWeight) TrailerTruck(license#, owner, color, weight, nTrailers)

Relational Schema for Type Hierarchy I Vehicle(license#, owner, color) Car(license#, owner, color, nPassengers, style) Truck(license#, owner, color, weight) DumpTruck(license#, owner, color, weight, loadWeight) TrailerTruck(license#, owner, color, weight, nTrailers) Get all information on all trailertrucks. select * from TrailerTruck;

Relational Schema for Type Hierarchy I Vehicle(license#, owner, color) Car(license#, owner, color, nPassengers, style) Truck(license#, owner, color, weight) DumpTruck(license#, owner, color, weight, loadWeight) TrailerTruck(license#, owner, color, weight, nTrailers) Get license# and owner of all vehicles. select licence#, owner, color from Vehicle union select licence#, owner, color from Car select licence#, owner, color from Truck select licence#, owner, color from DumpTruck select licence#, owner, color from TrailerTruck;

Relational Schema for Type Hierarchy II Vehicle(license#, owner, color) Car(license#, nPassengers, style) Truck(license#, weight) DumpTruck(license#, loadWeight) TrailerTruck(license#, nTrailers) The information on one entity is stored in multiple tables. When a class hierarchy is relatively flat, query statements in SQL become simpler

SQL Queries for Type II Class Hierarchy Vehicle(license#, owner, color) Car(license#, nPassengers, style) Truck(license#, weight) DumpTruck(license#, loadWeight) TrailerTruck(license#, nTrailers) Get all information on all trailertrucks. select v.licence#, owner, color, weight, nTrailers from Vehicle v, Truck t, TrailerTruck tt where v.license# = t.license# and t.license# = tt.license#

SQL Queries for Type II Class Hierarchy Vehicle(license#, owner, color) Car(license#, nPassengers, style) Truck(license#, weight) DumpTruck(license#, loadWeight) TrailerTruck(license#, nTrailers) Get license# and owner of all vehicles. select licens#, owner from Vehicle;

Ex: Convert ER Diagram to Relational Schema A – G are entity types. P, Q, and R are relationship types. Entity types B and D are subtypes of A, and entity type C is a subtype of B. Attributes are shown as a1, a2, ... Primary key attributes are marked with “*”. F is a weak entity-type of E. Attribute f1 of F marked with “**” is a weak-entity key. Construct the relational schema using minimum number of tables.

Ex: Convert ER Diagram to Relational Schema A(a1, a2) B(a1, b1, b2) C(a1, c1, c2) D(a1, d1, e1, f1, q1) E(e1, e2) F(e1,f1, f2) G(g1, g2) R(e1, f1, g1, r1)