The Entity-Relationship Model. Steps in Database Design

Similar documents
The Entity-Relationship Model

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

The Entity-Relationship Model

The Entity-Relationship (ER) Model

The Entity-Relationship Model. Overview of Database Design

MIS Database Systems Entity-Relationship Model.

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

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

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

Database Applications (15-415)

Database Management Systems. Chapter 2 Part 2

Introduction to Database Design

Introduction to Database Design

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

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

Introduction to Database Design

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

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

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

OVERVIEW OF DATABASE DEVELOPMENT

Database Management Systems. Chapter 3 Part 2

The Entity-Relationship Model

High Level Database Models

CSE 530A. ER Model. Washington University Fall 2013

The Entity-Relationship (ER) Model 2

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

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

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

High-Level Database Models (ii)

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

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

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

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

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

Database Design CENG 351

Modeling Your Data. Chapter 2. cs542 1

Database Applications (15-415)

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

CIS 330: Applied Database Systems

The Relational Model 2. Week 3

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

Entity-Relationship Diagrams

CSIT5300: Advanced Database Systems

COMP Instructor: Dimitris Papadias WWW page:

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

CMPT 354 Database Systems I

The Relational Model. Chapter 3

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

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

Conceptual Design. The Entity-Relationship (ER) Model

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

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

ER Model. CSC 343 Winter 2018 MICHAEL LIUT

CONCEPTUAL DESIGN: ER TO RELATIONAL TO SQL

Chapter 2: Entity-Relationship Model

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

Database Systems. Course Administration

The Relational Model (ii)

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

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

Database Management Systems. Syllabus. Instructor: Vinnie Costa

Database Applications (15-415)

COMP 244. ER-Diagram Notations. Entity-Relationship Diagrams DATABASE CONCEPTS & APPLICATIONS. Database Concepts & Applications 1.

Database Design & Deployment

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

CSC 261/461 Database Systems Lecture 10

Overview of Database Design Process Example Database Application (COMPANY) ER Model Concepts

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

COMP 244 DATABASE CONCEPTS & APPLICATIONS

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

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

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

Database Applications (15-415)

Entity Relationship Data Model. Slides by: Shree Jaswal

Roadmap of This Lecture. Weak Entity Sets Extended E-R Features Reduction to Relation Schemas Database Design UML*

Chapter Outline. Note 1. Overview of Database Design Process Example Database Application (COMPANY) ER Model Concepts

Review The Big Picture

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

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

Conceptual Data Models for Database Design

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

MIT Database Management Systems Lesson 03: Entity Relationship Diagrams

CSC 261/461 Database Systems Lecture 8. Fall 2017

ER to Relational Mapping. ER Model: Overview

Chapter 6: Entity-Relationship Model

Chapter 6: Entity-Relationship Model

! Need to decide. " What are relations. " What are columns/attributes in relations. " What integrity constraints or business rules hold?

Chapter 7: Entity-Relationship Model

Chapter 7: Entity-Relationship Model

Enhanced Entity- Relationship Models (EER)

CS2 Current Technologies Lecture 5: Data Modelling and Design

Entity-Relationship Model

Chapter 7: Entity-Relationship Model

Conceptual Modeling in ER and UML

Chapter 7: Entity-Relationship Model

CS 146 Database Systems

Introduction to Databases

Database Systems ( 資料庫系統 )

CS 4604: Introduction to Database Management Systems. B. Aditya Prakash Lecture #5: Entity/Relational Models---Part 1

Chapter 2. Database Design. Database Systems p. 25/540

Transcription:

The Entity-Relationship Model Steps in Database Design 1) Requirement Analysis Identify the data that needs to be stored data requirements Identify the operations that need to be executed on the data functional requirements 2) Conceptual Database Design Use a semantic data model to develop semantic schema 3) Map semantic schema to relational schema 2 1

Requirement Analysis Similar to first phase of general software design tools: data flow diagram, sequence diagrams, scenarios, etc. focus: data & functional requirements Questions to ask: 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? 3 Requirement Analysis: Student Database The database contains information about persons: Data: each person has an identifying ID each person has a PIN,, permanent address + phone number, 0 or more emergency contacts Functionality all data can be viewed and changed A person can be a student. A student has Data: a permanent code, an email, (account information) for past terms: courses taken and grades Term gpa cum gpa up to this term total credits up to this term for current term: a faculty, 0 or more programs, courses registered 4 2

Student Database (contd) A person can be an employee: it has an employee email address, pay information etc. A person can be a faculty: Only faculty can teach a course 5 Requirement Analysis: Student Database A course Functionality: students can register in course 6 3

Entity-Relationship Model (ER) Transform analysis information into the ER semantic schema ER A database schema in the ER Model can be represented pictorially (ER diagrams) An ER schema should be understandable by noncomputer scientists. We can map an ER diagram into a relational schema 7 Entity Entity: Real-world object distinguishable from other objects. An entity is described using a set of attributes. Entity Set: A collection of similar entities, e.g., all employees (similarity to a class in OO) All entities in an entity set have the same attributes (until we consider ISA hierarchies later ). An attribute describes a property of the entity set. Each entity set has a key: Minimum set of attributes whose values uniquely identify an entity in the set Each attribute has a domain: Integer, 20-character string eid salary Entity set = rectangle, Attribute = oval 8 4

ISA ( is a ) Hierarchies: Subclasses Subclass = special case = fewer entities = more properties A ISA B, then every A entity is also a B entity Key only in B. hours_worked hourly_wages Reasons for using Subclasses: Additional descriptive attributes specific for a subclass Identification of a subclass that participates in a relationship (will see later) Where do the entities reside: E/R-viewpoint: An entity has a component in each entity set to which it logically belongs. Its properties are the union of these entity sets. Contrast OO-viewpoint: An object belongs to exactly one class. The subclass inherits the attributes of its superclass. eid Hourly_Emps ISA Contract_id Contract_Emps salary 9 ISA Hierarchies (Contd.) Overlap Constraint: Can an entity be in more than one subclass? (allowed/disallowed) Covering Constraint: Must every entity of the superclass be in one of the subclasses? (yes/no) Developing Class Hierarchies Specialization: Identifying subsets of an entity set (the superclass) that share some distinguishing characteristic. Represents top-down design: superclass is first, then subclasses are defined and specific attributes and relationships are set. Generalization: Several entity sets are generalized into a common entity set. Represents bottom-up design: common characteristics of a collection of entity sets are identified, a superclass entity set is built with these characteristics as attributes. Theoretically multiple inheritance possible, in practice not used 10 5

Relationship Relationship: Association among two or more entities. E.g. Employee A works in department X. 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 the same set. eid salary Works_in did d budget 11 ER Model (contd.) with different roles in a relationship eid salary supervisor subordinate Reports_To Role indicator: supervisor/subordinate 12 6

Multiplicity: Many-to-many Works_In: Each entity of can have relationships many entities from Employee A works in departments X and Y Each entity of can have relationships with many entities from Department X has several employees that work there (e.g., employees A and B) Many-many relationship between departments and employees Note: A relationship is uniquely defined by the primary keys of participating entities Employee A cannot work twice in the department X Many to many eid salary Works_In did d budget 13 Multiplicity: one-to-many,many-to-one Manages: One employee can manage several departments; each department is managed by only one employee; One-to-many relationship between employee and department Many-to-one relationship between department and employee; The condition each department is managed by only one employee is called a key constraint on Manages and depicted with arrow from to Manages One to many eid salary Manages did d budget 14 7

Multiplicity: one-to-one Manages-2: Each employee can only manage one department; each department is managed by only one employee; One-to-one relationship between and Key constraints in both directions One to one eid salary Manages did d budget 15 Participation Constraints Works_in2: Each employee must work in at least one department the participation constraint requires that the participation of Employee in Works_in2 is total (vs. partial) (depicted with a thick line) eid salary Works_In did d budget 16 8

Participation Constraints Works_in3: Each employee works in exactly one department key constraint: at most once participation constraint: at least one combined: exactly once eid salary Works_In did d budget 17 Weak Entities A weak entity can be identified uniquely only by considering the primary key of another (owner) entity. The key in weak entity set is the union of the key of the owner entity set and a set of its own attributes (underlined with dashes) Owner entity set and weak entity set must participate in a supporting one-to-many relationship set (one owner, many weak entities). Weak entity set must have total participation in this identifying set. eid salary cost p dateofbirth Policy Dependants 18 9

Ternary Relationship 3-ary relationship eid salary Works_in address Location capacity did budget d Examples Employee A works in department X at the Montreal location Employee B works in department X and the Toronto location Note that given relationshipset is many-manymany Employee A works in department X at the Montreal location and in department Y at the Montreal location Or Employee A works in department X at the Montreal location and in department Y at the Lachine location 19 Aggregation Aggregation allows us to treat a relationship set R as an entity set so that R can participate in (other relationships). Example Each department can sponsor many projects Each project is sponsored by at least one dep Each sponsorship is monitored by at least one employee Aggregation vs. ternary relationship: Monitors is a distinct relationship with a descriptive attribute Can provide additional multiplicity constraints eid salary Monitors until pid Started_on pbudget Projects Sponsors did d budget 20 10

Conceptual Design with ER Design Principles: Keep it simple Avoid redundancies Capture as many constraints as possible Design Choices Entity or attribute? Attributes and relationships Identifying relationships: Binary or ternary? Aggregation? 21 Avoid redundancies Design Principles pid s Parts saddress Left side: Avoid Redundancy s Suppliers address offer pid Parts The address of a supplier is stored with each part it provides; if the supplier provides more than one part, then the address is stored several times Right side: By making supplier its own entity-set all supplier related information is stored only once. 22 11

Design Principles Keep it simple s Suppliers offer pid Parts Keep it simple pid Parts s Left side: The only information that exists about a supplier is its and that is the primary key. Right side: For each part we keep the supplier in an extra attribute. As there is no other information about suppliers there is no redundancy 23 Relationships and Attributes mbudget eid salary Manages did d budget eid salary mbudget ISA Managers Manages did d budget 24 12

Entity vs. Attribute Should address be an attribute of or an entity (connected to by a relationship)? Depends on the use and the semantics of the information If we an arbitrary number of addresses for each employee, address must be an entity ( attributes cannot be set-valued). If address represents a lodging or place of business and hence is a real object that is independent of the people who live or work there, then it should be an entity Note, it we want to capture the structure of address (because we want to retrieve all employees in a given city), we must use several separate attributes (street, zip, city, etc.). This can happen within the entity or as an extra entity. 25 Entity vs. Relationship sid quantity pid Suppliers Order Parts did Department d sid date quantity oid pid Suppliers Order Parts did Department d 26 13

Binary vs. Ternary vs. Aggregation Situation : Stars play in movies and movies are produced by studios Several constraints possible: Each movie is only produced by one studio or A star has only a single contract for a movie (even if several studios involved) or A contract for a movie is always between a star and a single studio (even if several studios involved) Solution I: Ternary relation Each arrow would lead to a nonsense restriction Consequence: Each movie can be produced by several studios But only possible if at least one star has contract with this studio for this movie Stars Studios Movies 27 Solution II: Binary vs. Ternary vs. Aggregation Two binary relations Stars movie produced by one studio possible A star plays now exactly once for a movie (with one contract) play But if several studios produce a movie we cannot express with which studio the contract is done Solution III: Aggregation Movies movie produced by one studio possible Star can have one or more contracts for a movie; each with a different studio Movies produce play Studios produce Studios stars 28 14

Binary vs. Ternary Relationships Situation I: employee can own several policies eid salary each policy can be owned by several employees covers each dependent can be covered by several policies a policy can cover several dependents pid Situation II: Policies employee can own several policies each policy has only one owner each dependent is identified by its policy eid salary a policy can cover several dependents p dob Dependents cost p dob Dependents purchaser beneficiary pid Policies cost 29 15