Conceptual Design Using the Entity-Relationship (ER) Model



Similar documents
The Entity-Relationship Model

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

The Entity-Relationship Model

Review: Participation Constraints

Lecture 6. SQL, Logical DB Design

The Relational Model. Ramakrishnan&Gehrke, Chapter 3 CS4320 1

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

Winter Winter

Outline. Data Modeling. Conceptual Design. ER Model Basics: Entities. ER Model Basics: Relationships. Ternary Relationships. Yanlei Diao UMass Amherst

Database Design Overview. Conceptual Design ER Model. Entities and Entity Sets. Entity Set Representation. Keys

Data Modeling. Database Systems: The Complete Book Ch ,

2. Conceptual Modeling using the Entity-Relationship Model

Introduction to Database Systems CS4320/CS5320. CS4320/4321: Introduction to Database Systems. CS4320/4321: Introduction to Database Systems

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

CSC 742 Database Management Systems

COMP 378 Database Systems Notes for Chapter 7 of Database System Concepts Database Design and the Entity-Relationship Model

Review Entity-Relationship Diagrams and the Relational Model. Data Models. Review. Why Study the Relational Model? Steps in Database Design

Database Design. Database Design I: The Entity-Relationship Model. Entity Type (con t) Chapter 4. Entity: an object that is involved in the enterprise

Schema Refinement and Normalization

CS 4604: Introduc0on to Database Management Systems. B. Aditya Prakash Lecture #5: En-ty/Rela-onal Models- - - Part 1

Chapter 7 Data Modeling Using the Entity- Relationship (ER) Model

Database Design. Goal: specification of database schema Methodology: E-R Model is viewed as a set of

Why Is This Important? Schema Refinement and Normal Forms. The Evils of Redundancy. Functional Dependencies (FDs) Example (Contd.)

There are five fields or columns, with names and types as shown above.

Chapter 2: Entity-Relationship Model. Entity Sets. " Example: specific person, company, event, plant

Bridge from Entity Relationship modeling to creating SQL databases, tables, & relations

Relational model. Relational model - practice. Relational Database Definitions 9/27/11. Relational model. Relational Database: Terminology

Databases and BigData

Schema Design and Normal Forms Sid Name Level Rating Wage Hours

Chapter 2: Entity-Relationship Model. E-R R Diagrams

SQL DDL. DBS Database Systems Designing Relational Databases. Inclusion Constraints. Key Constraints

Chapter 3. Data Modeling Using the Entity-Relationship (ER) Model

IV. The (Extended) Entity-Relationship Model

THE ENTITY- RELATIONSHIP (ER) MODEL CHAPTER 7 (6/E) CHAPTER 3 (5/E)

Database Design Process

DATABASE DESIGN. - Developing database and information systems is performed using a development lifecycle, which consists of a series of steps.

Database Design Process

The Entity-Relationship Model

Lesson 8: Introduction to Databases E-R Data Modeling

Chapter 2: Entity-Relationship Model

Foundations of Information Management

OVERVIEW 1.1 DATABASE MANAGEMENT SYSTEM (DBMS) DEFINITION:-

CSCI-GA Database Systems Lecture 7: Schema Refinement and Normalization

Lecture 12: Entity Relationship Modelling

not necessarily strictly sequential feedback loops exist, i.e. may need to revisit earlier stages during a later stage

IT2305 Database Systems I (Compulsory)

Entity Relationship Diagram

A brief overview of developing a conceptual data model as the first step in creating a relational database.

SQL DATA DEFINITION: KEY CONSTRAINTS. CS121: Introduction to Relational Database Systems Fall 2015 Lecture 7

Database Design Process. Databases - Entity-Relationship Modelling. Requirements Analysis. Database Design

Overview. Physical Database Design. Modern Database Management McFadden/Hoffer Chapter 7. Database Management Systems Ramakrishnan Chapter 16

Foundations of Information Management

Relational Database Concepts

Database Management Systems. Redundancy and Other Problems. Redundancy

Databases -Normalization III. (N Spadaccini 2010 and W Liu 2012) Databases - Normalization III 1 / 31

LiTH, Tekniska högskolan vid Linköpings universitet 1(7) IDA, Institutionen för datavetenskap Juha Takkinen

Database Design. Marta Jakubowska-Sobczak IT/ADC based on slides prepared by Paula Figueiredo, IT/DB

Lecture Notes INFORMATION RESOURCES

Entity-Relationship Model

EECS 647: Introduction to Database Systems

CS 377 Database Systems. Database Design Theory and Normalization. Li Xiong Department of Mathematics and Computer Science Emory University

IT2304: Database Systems 1 (DBS 1)

DataBase Management Systems Lecture Notes

TIM 50 - Business Information Systems

Designing a Database Schema

The E-R èentity-relationshipè data model views the real world as a set of basic objects èentitiesè and

Fundamentals of Database Design


BİL 354 Veritabanı Sistemleri. Entity-Relationship Model

Database Management System

The Relational Model. Why Study the Relational Model?

XV. The Entity-Relationship Model

DATABASE MANAGEMENT SYSTEMS. Question Bank:

Data Modeling: Part 1. Entity Relationship (ER) Model

ER modelling, Weak Entities, Class Hierarchies, Aggregation

DATABASE INTRODUCTION

6.830 Lecture PS1 Due Next Time (Tuesday!) Lab 1 Out today start early! Relational Model Continued, and Schema Design and Normalization

Database Design and the E-R Model

Data Modeling Basics

Database Design. Adrienne Watt. Port Moody

The Structured Query Language. De facto standard used to interact with relational DB management systems Two major branches

Week 11: Normal Forms. Logical Database Design. Normal Forms and Normalization. Examples of Redundancy

How To Improve Performance In A Database

Course: CSC 222 Database Design and Management I (3 credits Compulsory)

Requirement Analysis & Conceptual Database Design. Problem analysis Entity Relationship notation Integrity constraints Generalization

Schema Refinement, Functional Dependencies, Normalization

Introduction to Databases

Normalization. Reduces the liklihood of anomolies

CMU - SCS / Database Applications Spring 2013, C. Faloutsos Homework 1: E.R. + Formal Q.L. Deadline: 1:30pm on Tuesday, 2/5/2013

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer

Normalization in OODB Design

A Tool for Generating Relational Database Schema from EER Diagram

Logical Schema Design: The Relational Data Model

Chapter 15 Basics of Functional Dependencies and Normalization for Relational Databases

Chapter 6: Integrity Constraints

Relational Database Design: FD s & BCNF

Chapter 1: Introduction. Database Management System (DBMS) University Database Example

Transcription:

Conceptual Design Using the Entity-Relationship (ER) Model Module 5, Lectures 1 and 2 Database Management Systems, R. Ramakrishnan 1

Overview of Database Design 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. Schema Refinement: (Normalization) Check relational schema for redundancies and related anomalies. Physical Database Design and Tuning: Consider typical workloads and further refine the database design. Database Management Systems, R. Ramakrishnan 2

ER Model Basics ssn Entity: Real-world object distinguishable from other objects. An entity is described (in DB) using a set of attributes. 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. Can map entity set to a relation easily. ssn 123-22-3666 Attishoo 48 231-31-5368 Smiley 22 131-24-3650 Smethurst 35 CREATE TABLE (ssn CHAR(11), CHAR(20), INTEGER, PRIMARY KEY (ssn)) Database Management Systems, R. Ramakrishnan 3

ER Model Basics (Contd.) ssn ssn since did d budget subordinate supervisor Works_In Departments Reports_To Relationship: Association among 2 or more entities. E.g., Attishoo works in Pharmacy department. 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 E1,..., en En Same entity set could participate in different relationship sets, or in different roles in same set. Database Management Systems, R. Ramakrishnan 4

ER Model Basics (Contd.) Relationship sets can also have descriptive attributes (e.g., the since attribute of Works_In). 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 superkey for the relation. All descriptive attributes. CREATE TABLE Works_In( ssn CHAR(1), did INTEGER, since DATE, PRIMARY KEY (ssn, did), FOREIGN KEY (ssn) REFERENCES, FOREIGN KEY (did) REFERENCES Departments) ssn did since 123-22-3666 51 1/1/91 123-22-3666 56 3/3/93 231-31-5368 51 2/2/92 Database Management Systems, R. Ramakrishnan 5

Key Constraints since d ssn did budget Consider Works_In: An employee can work in many departments; a dept can have many employees. In contrast, each dept has at most one manager, according to the Manages key constraint on 1-to-1 1-to Many Many-to-1 Manages. Translation to relational model? Departments Many-to-Many Database Management Systems, R. Ramakrishnan 6

Translating ER Diagrams with Key Constraints Map relationship to a table: Note that did is the key now! Separate tables for and Departments. Since each department has a unique manager, we could instead combine Manages and Departments. CREATE TABLE Manages( ssn CHAR(11), did INTEGER, since DATE, PRIMARY KEY (did), FOREIGN KEY (ssn) REFERENCES, FOREIGN KEY (did) REFERENCES Departments) CREATE TABLE Dept_Mgr( did INTEGER, d CHAR(20), budget REAL, ssn CHAR(11), since DATE, PRIMARY KEY (did), FOREIGN KEY (ssn) REFERENCES ) Database Management Systems, R. Ramakrishnan 7

Participation Constraints 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 ssn value!) ssn since did d budget Manages Departments Works_In since Database Management Systems, R. Ramakrishnan 8

Participation Constraints in SQL 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, ssn CHAR(11) NOT NULL, since DATE, PRIMARY KEY (did), FOREIGN KEY (ssn) REFERENCES, ON DELETE NO ACTION) Database Management Systems, R. Ramakrishnan 9

Weak Entities 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. ssn cost p age Policy Dependents Database Management Systems, R. Ramakrishnan 10

Translating Weak Entity Sets 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, ssn CHAR(11) NOT NULL, PRIMARY KEY (p, ssn), FOREIGN KEY (ssn) REFERENCES, ON DELETE CASCADE) Database Management Systems, R. Ramakrishnan 11

ssn ISA (`is a ) Hierarchies As in C++, or other PLs, attributes are inherited. If we declare A ISA B, every A entity is also considered to be a B entity. (Query answers should reflect this: unlike C++!) hourly_wages hours_worked Hourly_Emps Contract_Emps Database Management Systems, R. Ramakrishnan 12 ISA contractid Overlap constraints: Can Joe be an Hourly_Emps as well as a Contract_Emps entity? (Allowed/disallowed) Covering constraints: Does every entity also have to be an Hourly_Emps or a Contract_Emps entity? (Yes/no) Reasons for using ISA: To add descriptive attributes specific to a subclass. To identify entitities that participate in a relationship.

Translating ISA Hierarchies to Relations 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, ssn); 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. Alternative: Just Hourly_Emps and Contract_Emps. Hourly_Emps: ssn,,, hourly_wages, hours_worked. Each employee must be in one of these two subclasses. Database Management Systems, R. Ramakrishnan 13

ssn Aggregation Used when we have to model a relationship involving (entitity sets and) a relationship set. Aggregation allows us to treat a relationship set as an entity set for purposes of participation in (other) relationships. Monitors mapped to table like any other relationship set. pid started_on Projects Monitors pbudget Sponsors budget Aggregation vs. ternary relationship: Monitors is a distinct relationship, with a descriptive attribute. Also, can say that each sponsorship is monitored by at most one employee. Database Management Systems, R. Ramakrishnan 14 did until d Departments

Conceptual Design Using the ER Model Design choices: Should a concept be modelled as an entity or an attribute? Should a concept be modelled as an entity or a relationship? Identifying relationships: Binary or ternary? Aggregation? Constraints in the ER Model: A of data semantics can (and should) be captured. But some constraints cannot be captured in ER diagrams. Need for further refining the schema: Relational schema obtained from ER diagram is a good first step. But ER design subjective & can t express certain constraints; so this relational schema may need refinement. Database Management Systems, R. Ramakrishnan 15

Entity vs. Attribute Should address be an attribute of or an entity (connected to by a relationship)? Depends upon the use we want to make of address information, and the semantics of the data: If we have several addresses per employee, address must be an entity (since attributes cannot be set-valued). If the structure (city, street, etc.) is important, e.g., we want to retrieve employees in a given city, address must be modelled as an entity (since attribute values are atomic). Database Management Systems, R. Ramakrishnan 16

Entity vs. Attribute (Contd.) Works_In2 does not allow an employee to work in a department for two or more periods. Similar to the problem of wanting to record several addresses for an employee: we want to record several values of the descriptive attributes for each instance of this relationship. ssn ssn from from to Works_In2 Works_In3 Duration did did d budget Departments to d budget Departments Database Management Systems, R. Ramakrishnan 17

Entity vs. Relationship First ER diagram OK if a manager gets a separate discretionary budget for each dept. What if a manager gets a discretionary budget that covers all managed depts? ssn ssn Redundancy of dbudget, which is stored for each dept managed by the manager. Misleading: suggests dbudget tied to managed dept. Manages2 d budget Database Management Systems, R. Ramakrishnan 18 apptnum since dbudget Manages3 Mgr_Appts did did Departments d since budget Departments dbudget

Binary vs. Ternary Relationships If each policy is owned by just 1 employee: Key constraint on Policies would mean policy can only cover 1 dependent! What are the additional constraints in the 2nd diagram? ssn ssn Bad design Covers p policyid cost Database Management Systems, R. Ramakrishnan 19 policyid Purchaser Better design Policies Policies cost Beneficiary p age Dependents age Dependents

Binary vs. Ternary Relationships (Contd.) The key constraints allow us to combine Purchaser with Policies and Beneficiary with Dependents. Participation constraints lead to NOT NULL constraints. What if Policies is a weak entity set? CREATE TABLE Policies ( policyid INTEGER, cost REAL, ssn CHAR(11) NOT NULL, PRIMARY KEY (policyid). FOREIGN KEY (ssn) REFERENCES, ON DELETE CASCADE) CREATE TABLE Dependents ( p CHAR(20), age INTEGER, policyid INTEGER, PRIMARY KEY (p, policyid). FOREIGN KEY (policyid) REFERENCES Policies, ON DELETE CASCADE) Database Management Systems, R. Ramakrishnan 20

Binary vs. Ternary Relationships (Contd.) Previous example illustrated a case when 2 binary relationships were better than a ternary relationship. An example in the other direction: a ternary relation Contracts relates entity sets Parts, Departments and Suppliers, and has descriptive attribute qty. No combination of binary relationships is an adequate substitute: S ``can-supply P, D ``needs P, and D ``deals-with S does not imply that D has agreed to buy P from S. How do we record qty? Database Management Systems, R. Ramakrishnan 21

Constraints Beyond the ER Model Functional dependencies: e.g., A dept can t order two distinct parts from the same supplier. Can t express this wrt ternary Contracts relationship. Normalization refines ER design by considering FDs. Inclusion dependencies: Special case: Foreign keys (ER model can express these). e.g., At least 1 person must report to each manager. (Set of ssn values in Manages must be subset of supervisor_ssn values in Reports_To.) Foreign key? Expressible in ER model? General constraints: e.g., Manager s discretionary budget less than 10% of the combined budget of all departments he or she manages. Database Management Systems, R. Ramakrishnan 22

Summary of Conceptual Design Conceptual design follows requirements analysis, Yields a high-level description of data to be stored ER model popular for conceptual design Constructs are expressive, close to the way people think about their applications. Basic constructs: entities, relationships, and attributes (of entities and relationships). Some additional constructs: weak entities, ISA hierarchies, and aggregation. Note: There are many variations on ER model. Database Management Systems, R. Ramakrishnan 23

Summary of ER (Contd.) 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 of these constraints can be expressed in SQL only if we use general CHECK constraints or assertions. 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. Database Management Systems, R. Ramakrishnan 24

Summary of ER (Contd.) 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, binary or n-ary relationship, whether or not to use ISA hierarchies, and whether or not to use aggregation. Ensuring good database design: resulting relational schema should be analyzed and refined further. FD information and normalization techniques are especially useful. Database Management Systems, R. Ramakrishnan 25