The Entity-Relationship Model

Similar documents
The Entity-Relationship Model. Overview of Database Design

The Entity-Relationship Model

The Entity-Relationship Model. Overview of Database Design. ER Model Basics. (Ramakrishnan&Gehrke, Chapter 2)

The Entity-Relationship Model

Database Management Systems. Chapter 3 Part 2

High-Level Database Models (ii)

High Level Database Models

Contents. Database. Information Policy. C03. Entity Relationship Model WKU-IP-C03 Database / Entity Relationship Model

The Entity-Relationship (ER) Model

From ER to Relational Model. Book Chapter 3 (part 2 )

CIS 330: Web-driven Web Applications. Lecture 2: Introduction to ER Modeling

OVERVIEW OF DATABASE DEVELOPMENT

Overview of db design Requirement analysis Data to be stored Applications to be built Operations (most frequent) subject to performance requirement

Introduction to Database Design

The Relational Model (ii)

Introduction to Data Management. Lecture #4 (E-R à Relational Design)

The Relational Model 2. Week 3

CS/INFO 330 Entity-Relationship Modeling. Announcements. Goals of This Lecture. Mirek Riedewald

CONCEPTUAL DESIGN: ER TO RELATIONAL TO SQL

The Relational Model. Chapter 3

The Relational Model. Chapter 3. Database Management Systems, R. Ramakrishnan and J. Gehrke 1

CIS 330: Applied Database Systems

Introduction to Database Design. Dr. Kanda Runapongsa Dept of Computer Engineering Khon Kaen University

CIS 330: Applied Database Systems. ER to Relational Relational Algebra

Database Management Systems. Chapter 2 Part 2

The Relational Model. Why Study the Relational Model? Relational Database: Definitions

Introduction to Data Management. Lecture #5 (E-R Relational, Cont.)

Data Modeling. Yanlei Diao UMass Amherst. Slides Courtesy of R. Ramakrishnan and J. Gehrke

Introduction to Data Management. Lecture #3 (Conceptual DB Design) Instructor: Chen Li

The Relational Model. Chapter 3. Comp 521 Files and Databases Fall

Database Design & Deployment

Databases Model the Real World. The Entity- Relationship Model. Conceptual Design. Steps in Database Design. ER Model Basics. ER Model Basics (Contd.

The Relational Model. Chapter 3. Comp 521 Files and Databases Fall

Database Applications (15-415)

Introduction to Data Management. Lecture #3 (Conceptual DB Design)

Databases Model the Real World. The Entity- Relationship Model. Conceptual Design. Steps in Database Design. ER Model Basics. ER Model Basics (Contd.

The Relational Model. Roadmap. Relational Database: Definitions. Why Study the Relational Model? Relational database: a set of relations

Entity-Relationship Diagrams

MIS Database Systems Entity-Relationship Model.

Why Study the Relational Model? The Relational Model. Relational Database: Definitions. The SQL Query Language. Relational Query Languages

The Relational Model. Outline. Why Study the Relational Model? Faloutsos SCS object-relational model

The Entity-Relationship Model. Steps in Database Design

Introduction to Data Management. Lecture #3 (Conceptual DB Design)

Introduction to Data Management. Lecture #6 E-Rà Relational Mapping (Cont.)

Database Design. ER Model. Overview. Introduction to Database Design. UVic C SC 370. Database design can be divided in six major steps:

CSC 261/461 Database Systems Lecture 10

Relational Model. Topics. Relational Model. Why Study the Relational Model? Linda Wu (CMPT )

Relational Databases BORROWED WITH MINOR ADAPTATION FROM PROF. CHRISTOS FALOUTSOS, CMU /615

ER Model Overview. The Entity-Relationship Model. Database Design Process. ER Model Basics

The Entity-Relationship (ER) Model 2

Overview. Introduction to Database Design. ER Model. Database Design

Database Systems. Course Administration

Introduction to Database Design

Database Design CENG 351

ER to Relational Mapping. ER Model: Overview

Introduction to Databases

Database Applications (15-415)

Introduction to Database Design

SYLLABUS ADMIN DATABASE SYSTEMS I WEEK 2 THE ENTITY-RELATIONSHIP MODEL. Assignment #2 changed. A2Q1 moved to A3Q1

Database Systems ( 資料庫系統 )

Database Management Systems. Syllabus. Instructor: Vinnie Costa

CSE 530A. ER Model. Washington University Fall 2013

Conceptual Design. The Entity-Relationship (ER) Model

Conceptual Design. The Entity-Relationship (ER) Model

Database Management Systems. Session 2. Instructor: Vinnie Costa

Translating an ER Diagram to a Relational Schema

VARDHAMAN COLLEGE OF ENGINEERING Shamshabad , Hyderabad B.Tech. CSE IV Semester (VCE - R11) T P C 3+1* -- 4 (A1511) DATABASE MANAGEMENT SYSTEMS

Database Systems. Lecture2:E-R model. Juan Huo( 霍娟 )

Introduction to Data Management. Lecture #3 (E-R Design, Cont d.)

CSE 530A. ER Model to Relational Schema. Washington University Fall 2013

COMP Instructor: Dimitris Papadias WWW page:

CS 146 Database Systems

Database Applications (15-415)

Review The Big Picture

LAB 3 Notes. Codd proposed the relational model in 70 Main advantage of Relational Model : Simple representation (relationstables(row,

ER Model. CSC 343 Winter 2018 MICHAEL LIUT

Translation of ER-diagram into Relational Schema. Dr. Sunnie S. Chung CIS430/530

CSC 261/461 Database Systems Lecture 8. Fall 2017

Modeling Your Data. Chapter 2. cs542 1

CSC 261/461 Database Systems Lecture 8. Spring 2018

CSIT5300: Advanced Database Systems

Database Applications (15-415)

Chapter 9: Relational DB Design byer/eer to Relational Mapping Relational Database Design Using ER-to- Relational Mapping Mapping EER Model

Integrity constraints, relationships. CS634 Lecture 2

The Relational Model

The Relational Model

ENTITY-RELATIONSHIP. The database design process can be divided into six steps. The ER model is most relevant to the first three steps:

DATABASE MANAGEMENT SYSTEMS

Relational DB Design by ER- and EER-to-Relational Mapping Design & Analysis of Database Systems

Introduction to Data Management. Lecture #4 E-R Model, Still Going

ER to Relational Mapping

The Relational Model

Agent 7 which languages? skills?

Introduction to Data Management. Lecture #2 (Big Picture, Cont.)

SQL DDL. CS3 Database Systems Weeks 4-5 SQL DDL Database design. Key Constraints. Inclusion Constraints

CS2 Current Technologies Lecture 5: Data Modelling and Design

Introduction to Data Management. Lecture #4 (E-R Relational Translation)

Informatics 1: Data & Analysis

2. DatabaseDesign. Master I Software Engineering. Dr. Imed Bouchrika Dept of Mathematics & Computer Science University of Souk-Ahras

CMPT 354 Database Systems I

Transcription:

The Entity-Relationship Model Chapter 2 Instructor: Vladimir Zadorozhny vladimir@sis.pitt.edu Information Science Program School of Information Sciences, University of Pittsburgh 1 Database: a Set of Relations (Tables) Find the of the customer with customer-id 192-83-7465 select customer.customer_ from customer where customer.customer_id = 192-83-7465 2

Database Design The process of designing the general structure of the database: v Requires that we find a good collection of relation schemas. Business decision What attributes should we record in the database? IS decision What relation schemas should we have and how should the attributes be distributed among the various relation schemas? v Deciding on the physical layout of the database 3 Conceptual Database Design v Conceptual design: (ER Model is used at this stage.) What are the entities and relationships in the enterprise? What information about these entities and relationships should we store in the database? What are the integrity constraints or business rules that hold? A database `schema in the ER Model can be represented pictorially (ER diagrams). Can map an ER diagram into a relational schema. 4

ER Model Basics v Entity: Real-world object distinguishable from other objects. An entity is described (in DB) using a set of attributes. v Entity Set: A collection of similar entities. E.g., all employees. All entities in an entity set have the same set of attributes. (Until we consider ISA hierarchies, anyway!) Each entity set has a key. Each attribute has a domain. 5 ER Model Basics (Contd.) did d budget subordinate supervisor Works_In Departments Reports_To v Relationship: Association among two or more entities. E.g., Attishoo works in Pharmacy department. v Relationship Set: Collection of similar relationships. An n-ary relationship set R relates n entity sets E1... En; each relationship in R involves entities e1 in E1,..., en in En Same entity set could participate in different relationship sets, or in different roles in same set. 6

Key Constraints d did budget v Consider Works_In: An employee can work in many departments; a dept can have many employees. v In contrast, each dept has at most one manager, according to the key constraint on Manages. Manages 1-to-1 1-to Many Many-to-1 Departments Many-to-Many 7 Participation Constraints v Does every department have a manager? If so, this is a participation constraint: the participation of Departments in Manages is said to be total (vs. partial). Every did value in Departments table must appear in a row of the Manages table (with a non-null value!) did d budget Manages Departments Works_In 8

Weak Entities v A weak entity can be identified uniquely only by considering the primary key of another (owner) entity. Owner entity set and weak entity set must participate in a one-tomany relationship set (one owner, many weak entities). Weak entity set must have total participation in this identifying relationship set. cost p age Policy Dependents 9 ISA (`is a ) Hierarchies As in C++, or other PLs, attributes are inherited. hourly_wages If we declare A ISA B, every A entity is also considered to be a B entity. hours_worked Hourly_Emps ISA contractid Contract_Emps v Overlap constraints: Can Joe be an Hourly_Emps as well as a Contract_Emps entity? (Allowed/disallowed) v Covering constraints: Does every entity also have to be an Hourly_Emps or a Contract_Emps entity? (Yes/no) v Reasons for using ISA: To add descriptive attributes specific to a subclass. To identify entitities that participate in a relationship. 10

Conceptual Design Using the ER Model v Design choices: Should a concept be modeled as an entity or an attribute? Should a concept be modeled as an entity or a relationship? v Constraints in the ER Model: A of data semantics can (and should) be captured. But some constraints cannot be captured in ER diagrams. 11 Summary of Conceptual Design v Conceptual design follows requirements analysis, Yields a high-level description of data to be stored v ER model popular for conceptual design Constructs are expressive, close to the way people think about their applications. v Basic constructs: entities, relationships, and attributes (of entities and relationships). v Some additional constructs: weak entities, ISA hierarchies. v Note: There are many variations on ER model. 12

Summary of ER (Contd.) v Several kinds of integrity constraints can be expressed in the ER model: key constraints, participation constraints, and overlap/covering constraints for ISA hierarchies. Some foreign key constraints are also implicit in the definition of a relationship set. Some constraints (notably, functional dependencies) cannot be expressed in the ER model. Constraints play an important role in determining the best database design for an enterprise. 13 Summary of ER (Contd.) v ER design is subjective. There are often many ways to model a given scenario! Analyzing alternatives can be tricky, especially for a large enterprise. Common choices include: Entity vs. attribute, entity vs. relationship, whether or not to use ISA hierarchies. v Ensuring good database design: resulting relational schema should be analyzed and refined further. FD information and normalization techniques are especially useful. 14

Logical DB Design: ER to Relational v Entity sets to tables: CREATE TABLE ( CHAR(11), CHAR(20), INTEGER, PRIMARY KEY ()) 15 Relationship Sets to Tables d did budget v In translating a relationship set to a relation, attributes of the relation must include: Keys for each participating entity set (as foreign keys). This set of attributes forms a superkey for the relation. All descriptive attributes. Works_In Departments CREATE TABLE Works_In( CHAR(1), did INTEGER, DATE, PRIMARY KEY (, did), FOREIGN KEY () REFERENCES, FOREIGN KEY (did) REFERENCES Departments) 16

Review: Key Constraints v Each dept has at most one manager, according to the key constraint on Manages. Manages d did budget Departments Translation to relational model? 1-to-1 1-to Many Many-to-1 Many-to-Many 17 Translating ER Diagrams with Key Constraints v Map relationship to a table: Note that did is the key now! Separate tables for and Departments. v Since each department has a unique manager, we could instead combine Manages and Departments. CREATE TABLE Manages( CHAR(11), did INTEGER, DATE, PRIMARY KEY (did), FOREIGN KEY () REFERENCES, FOREIGN KEY (did) REFERENCES Departments) CREATE TABLE Dept_Mgr( did INTEGER, d CHAR(20), budget REAL, CHAR(11), DATE, PRIMARY KEY (did), FOREIGN KEY () REFERENCES ) 18

Review: Participation Constraints v Does every department have a manager? If so, this is a participation constraint: the participation of Departments in Manages is said to be total (vs. partial). Every did value in Departments table must appear in a row of the Manages table (with a non-null value!) did d budget Manages Departments Works_In 19 Participation Constraints in SQL v We can capture participation constraints involving one entity set in a binary relationship, but little else (without resorting to CHECK constraints). CREATE TABLE Dept_Mgr( did INTEGER, d CHAR(20), budget REAL, CHAR(11) NOT NULL, DATE, PRIMARY KEY (did), FOREIGN KEY () REFERENCES, ON DELETE NO ACTION) 20

Review: Weak Entities v A weak entity can be identified uniquely only by considering the primary key of another (owner) entity. Owner entity set and weak entity set must participate in a one-to-many relationship set (1 owner, many weak entities). Weak entity set must have total participation in this identifying relationship set. cost p age Policy Dependents 21 Translating Weak Entity Sets v Weak entity set and identifying relationship set are translated into a single table. When the owner entity is deleted, all owned weak entities must also be deleted. CREATE TABLE Dep_Policy ( p CHAR(20), age INTEGER, cost REAL, CHAR(11) NOT NULL, PRIMARY KEY (p, ), FOREIGN KEY () REFERENCES, ON DELETE CASCADE) 22

Review: ISA Hierarchies v As in C++, or other PLs, attributes are inherited. hourly_wages v If we declare A ISA B, every A entity is also considered to be a B entity. hours_worked Hourly_Emps ISA contractid Contract_Emps v Overlap constraints: Can Joe be an Hourly_Emps as well as a Contract_Emps entity? (Allowed/disallowed) v Covering constraints: Does every entity also have to be an Hourly_Emps or a Contract_Emps entity? (Yes/no) 23 Translating ISA Hierarchies to Relations v General approach: 3 relations:, Hourly_Emps and Contract_Emps. Hourly_Emps: Every employee is recorded in. For hourly emps, extra info recorded in Hourly_Emps (hourly_wages, hours_worked, ); must delete Hourly_Emps tuple if referenced tuple is deleted). Queries involving all employees easy, those involving just Hourly_Emps require a join to get some attributes. v Alternative: Just Hourly_Emps and Contract_Emps. Hourly_Emps:,,, hourly_wages, hours_worked. Each employee must be in one of these two subclasses. 24