MIS Database Systems Entity-Relationship Model.

Similar documents
The Entity-Relationship Model

The Entity-Relationship Model

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

The Entity-Relationship (ER) Model

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

Database Management Systems. Chapter 2 Part 2

Introduction to Database Design

The Entity-Relationship Model. Overview of Database Design

Database Applications (15-415)

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

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

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

The Entity-Relationship (ER) Model 2

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

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

Introduction to Database Design

Modeling Your Data. Chapter 2. cs542 1

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

OVERVIEW OF DATABASE DEVELOPMENT

Introduction to Database Design

The Entity-Relationship Model. Steps in Database Design

Introduction to Data Management. Lecture #3 (Conceptual DB 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

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

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

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

CSE 530A. ER Model. Washington University Fall 2013

Database Design CENG 351

The Entity-Relationship Model

Database Management Systems. Chapter 3 Part 2

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

Entity-Relationship Diagrams

CIS 330: Applied Database Systems

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

Database Applications (15-415)

High Level Database Models

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

ER Model. CSC 343 Winter 2018 MICHAEL LIUT

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

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

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

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

CONCEPTUAL DESIGN: ER TO RELATIONAL TO SQL

The Relational Model 2. Week 3

Database Applications (15-415)

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

Database Management Systems. Syllabus. Instructor: Vinnie Costa

The Relational Model. Chapter 3

COMP Instructor: Dimitris Papadias WWW page:

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

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

The Relational Model (ii)

Database Systems. Course Administration

CSIT5300: Advanced Database Systems

CMPT 354 Database Systems I

High-Level Database Models (ii)

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

ER to Relational Mapping. ER Model: Overview

Conceptual Design. The Entity-Relationship (ER) Model

Review The Big Picture

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

CSC 261/461 Database Systems Lecture 8. Spring 2018

Conceptual Design. The Entity-Relationship (ER) Model

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

CSC 261/461 Database Systems Lecture 8. Fall 2017

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

COMP 244 DATABASE CONCEPTS & APPLICATIONS

CSC 261/461 Database Systems Lecture 10

CS 146 Database Systems

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

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

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

1/24/2012. Chapter 7 Outline. Chapter 7 Outline (cont d.) CS 440: Database Management Systems

Database Applications (15-415)

Chapter 2: Entity-Relationship Model

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

Carnegie Mellon Univ. Dept. of Computer Science /615 - DB Applications. Problem. Faloutsos - Pavlo CMU SCS /615

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

Database Systems ( 資料庫系統 )

Problem. Carnegie Mellon Univ. Dept. of Computer Science /615 - DB Applications

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

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

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

Administrivia. Carnegie Mellon Univ. Dept. of Computer Science /615 - DB Applications. Course Topics. Problem

Entity Relationship Data Model. Slides by: Shree Jaswal

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

LAB 2 Notes. Conceptual Design ER. Logical DB Design (relational) Schema Refinement. Physical DD

Entity-Relationship Modelling. Entities Attributes Relationships Mapping Cardinality Keys Reduction of an E-R Diagram to Tables

LECTURE 3: ENTITY-RELATIONSHIP MODELING

Chapter 6: Entity-Relationship Model

Entity-Relationship Model

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

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

Chapter 7: Entity-Relationship Model

Chapter 7: Entity-Relationship Model

Chapter 7: Entity-Relationship Model

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

Conceptual Design with ER Model

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

Transcription:

MIS 335 - Database Systems Entity-Relationship Model http://www.mis.boun.edu.tr/durahim/ Ahmet Onur Durahim

Learning Objectives Database Design Main concepts in the ER model? ER Diagrams

Database Design and ER Diagrams Requirements Analysis: find out what the users want from the database What data is to be stored in the DB What applications must be built on top of it What operations are most frequent and subject to performance requirements Conceptual Database Design: create a simple description of the data that closely matches how users and developers think of the data A high-level (semantic) description of data to be stored in the DB along with the constraints known to hold over this data Carried out using the ER Model Logical Database Design: choose DBMS to implement conceptual database design Convert conceptual DB design (ER schema) into a DB schema in the data model of the chosen DBMS (relational DB schema)

DB Design Schema Refinement Analyze the collection of relations in relational DB schema to identify potential problems and refine it (- Normalization of the relations) Physical DB Design Consider expected workloads to refine for meeting the desired performance criteria Building indexes on tables Clustering some tables Redesign of parts of the DB schema Application and Security Design Identify entities (users, departments) and relevant roles of each entity Enforce access rules: For each role, identify the parts of the DB that must be accessible and must not be accessible

Entity-Relationship Model Before developing your database application, you need to Collect the requirements Build a conceptual database design ER Model: used to describe the data involved in an enterprise in terms of objects and relationships Widely accepted standard for initial (conceptual) database design

Entity-Relationship Model Conceptual DB design: 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

Entity-Relationship Diagram ssn lot cost p age Employees Policy Dependents

Key Concepts of ER Model Entities and Relationships Entities An object that is capable of independent existence and can be uniquely identified can be distinguished from other objects Employee Student Item An entity is described using a set of attributes ssn sid type

Entity set Key Concepts of ER Model A collection of similar entities share the same set of properties/attributes except in ISA hierarchies Reflects the level of detail at to represent information about entities Students Onur Alp Zubeyde Esra Arzu Ahmet

Key Concepts of ER Model Entity set may overlap Any example? Students Onur Zubeyde Arzu Alp Esra Ahmet Employees Mert Emrecan Mehmet

Key Concepts of ER Model Each entity sets has attributes Each attribute has a domain Domain: set of permitted values attribute (set of 20-character string) age attribute (set of integers between 0-150) Each entity set has a key minimal set of attributes whose values uniquely identify an entity in the set denoted by underlining the attribute in the ERdiagram Employee ssn address

Key Concepts of ER Model Relationships Association (relation) among two or more entities Ahmet is enrolled in MIS335 Enrolled Works_In Relationship sets A collection of similar relationships Share the same properties

Key Concepts of ER Model Relationships also has attributes Descriptive attributes: used to record the information about the relationship Ahmet Works_In University since 2014 Employee Works_In ssn address since

ER Model c sid Student Enrolled Course cid semester Rectangles : Entity sets Diamonds : Relationship Sets Ellipses/Oval : Attributes

ER Model Degree of a relationship set is the number of entity sets that participate in a relationship Binary relationship sets involve two entity sets sid Student Enrolled semester Course cid c

ER Model Ternary relationship sets involve three entity sets address Locations capacity Employee Works_In Departments ssn since did d budget

An Instance of the WorksIn Relationship Set

ER Model The set of entities that participate in a relationship set may belong to the same entity set Each entity plays a different role in such a relationship Employees ssn Employees supervisor subordinate Reports_To Reports_To => Unary relationship

ER Model The set of entities that participate in a relationship set may belong to the same entity set Each entity plays a different role in such a relationship Students sid Student tutor tutee Helps

Cardinality Mappings One-to-One (1-1) One occurrence of an entity relates to only one occurrence in another entity rarely exists in practice consider combining them into one entity Example: an employee is allocated a company car, which can only be driven by that employee One-to-Many (1-M) / Many-to-One (M-1) One occurrence in an entity relates to many occurrences in another entity Example: an employee works in one department but a department has many employees.

Cardinality Mappings Many-to-Many (M-N) Many occurrences in an entity relate to many occurrences in another entity The normalisation process would prevent any such relationships Rarely exist They occur because an entity has been missed. Example: an employee may work on several projects at the same time and a project has a team of many employees. In the normalisation process this many-to-many is resolved by the entity Project Team.

Cardinality Mappings 1-to-1 1-to-Many Many-to-1 Many-to-Many

ER Model Key Constraints Employees Works_In Departments ssn since did d since An employee can Work In multiple departments and a department can have multiple employees. What is the type of this relationship? Many-to-Many

ER Model Key Constraints Employees Manages Departments ssn since did d An employee can Manage multiple departments, but a department can be managed by only one employee (Manager) What is the type of this relationship? since This is called a key constraint (the restriction that each department has at most one manager) denoted by an arrow 1-to-Many

An Instance of the Manages Relationship Set Department with did = 60 violates the key constraint of the Manages relationship Instance of Manages relationship that satisfies the key constraint of the Manages relationship

Participation Constraints If every department is required to have a manager, this requirement is a participation constraint The participation of the entity set Departments in the relationship set Manages is total The participation of the entity set Employees in the relationship set Manages is partial Since not every employee gets to manage a department Total participation constraint of an Entity set in a relationship set is indicated by connecting them by thick line Employees Manages Departments ssn since did d since

Participation Constraints If each employee works in at least one department, and if each department has at least one employee Total or Partial Participation of Employees & Departments entities Works_In since Employees Manages Departments ssn since did d since

Weak Entities Weak Entity: Entity set that does not include a key A weak entity can be identified uniquely only by considering the primary key of another entity (called identifying owner) Set of attributes of a weak entity set that uniquely identify a weak entity for a given owner entity => partial key A weak entity set is denoted by a rectangle with thick lines Employees Policy Dependents ssn cost age p

Weak Entities A weak entity can be identified uniquely only by considering the primary key of another entity (called identifying owner) A weak entity set is denoted by a rectangle with thick lines The relationship between a weak entity and the owner entity is denoted by a diamond with thick lines Employees Policy Dependents ssn cost age p

Weak Entities A weak entity can be identified uniquely only by considering the primary key of another entity (called identifying owner) What can you say about the constraints on the identifying relationship? (i.e., participation and key constraints) Employees Policy Dependents ssn cost age p

Weak Entities What can you say about the constraints on the identifying relationship? (i.e., participation and key constraints) Owner entity set and weak entity set must participate in a one-to-many relationship set (one owner, many weak entities) Weak entity set must have total participation in this identifying relationship set Employees Policy Dependents ssn cost age p

Class/ISA ( is a ) Hierarchies Classify entities into subclasses Every entity in a subclass also belongs to superclass (Employees) The attributes for the entity set Employees are inherited by the entity set Hourly_Emps Hourly_Emps ISA Employees Reasons for using ISA: To add descriptive attributes specific to a subclass i.e. not appropriate for all entities in the superclass hourly_wages To identify entities that participate in a relationship i.e. not all superclass entities participate Hourly_Emps hours_worked ssn Employees ISA Contract_Emps contractid

Class/ISA ( is a ) Hierarchies Specialization: process of identifying subsets of an entity set (Employees) that share some distinguishing characteristic Employees is specialized into subclasses Generalization: process of identifying some common characteristics of a collection of entity sets and creating a new entity set that contains entities possessing these common characteristics Hourly_Emps and Contract_Emps are generalized by Employees Hourly_Emps ssn Employees ISA Contract_Emps hourly_wages hours_worked contractid

Class/ISA ( is a ) Hierarchies Overlap Constraints: determine whether two subclasses are allowed to contain the same entity Can Ahmet belong to both Contract_Emps entity and Hourly_Emps? Covering Constraints: determine whether the entities in the subclasses collectively include all entities in the superclass Does every Employees entity have to belong to one of Hourly_Emps and Contract_Emps? ssn Employees ISA Hourly_Emps Contract_Emps hourly_wages hours_worked contractid

Aggregation ssn Used to indicate that a relationship set (denoted by a dashed box) participates in another relationship set Allows us to treat a relationship set as an entity set for purposes of participation in other relationships A department that sponsors a project might assign employees to Monitor the Sponsorship Monitors should be a relationship that associates a Sponsors relationship with an Employees entity started_on Projects pbudget 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 pid Employees Monitors until Sponsors Departments did d since budget

Conceptual Design Using the ER Model Design choices: Should a concept be modeled as an entity or an attribute? Should a concept be modeled as an entity or a relationship? Identifying relationships: Binary or ternary? Aggregation? Constraints in the ER Model: A lot of data semantics can (and should) be captured But some constraints cannot be captured in ER diagrams

Entity vs. Attribute Should address be an attribute of Employees or an entity (connected to Employees by a relationship)? Depends upon the use we want to make of address information, and the semantics of the data: If only one address is to be recorded per employee Use attribute address If we have several addresses per employee address must be an entity (since attributes cannot be set-valued) If we want to capture the structure (break down address into country, city, street, etc.) of an address e.g., we want to retrieve employees in a given city address must be modeled as an entity (since attribute values are atomic)

Entity vs. Attribute Works_In does not allow an employee to work in a department for two or more periods This possibility is ruled out by the ER diagram s semantic, because relationship is uniquely identified by the participating entities (without reference to its descriptive attributes) 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 Accomplished by introducing new entity set, Duration Employees ssn from Employees ssn from to Works_In Duration Works_In Departments did d budget to Departments did d budget

Entity vs. Relationship ER diagram is OK if a manager gets a separate discretionary budget for each department What if a manager gets a discretionary budget that covers all managed departments? Redundancy: dbudget stored for each dept managed by manager Misleading: Suggests dbudget associated with departmentmgr combination Employees Employees ISA since dbudget Manages Departments ssn did d budget ssn Manages Departments did d since Managers dbudget budget

Entity vs. Relationship ER diagram is OK if a manager gets a separate discretionary budget for each department What if a manager gets a discretionary budget that covers all managed departments? Redundancy: dbudget stored for each dept managed by manager Misleading: Suggests dbudget associated with departmentmgr combination Redundancies are eliminated by Normalization technique Employees Employees ISA Managers since dbudget Manages Departments ssn did d budget ssn since Manages Departments did d dbudget budget

Binary vs. Ternary Relationship ssn p age Models the situation where; An employee can own several policies Each policy can be owned by several employees Each dependent can be covered by several policies Employees policyid Covers Policies cost Dependents

Binary vs. Ternary Relationship If we have additional requirements; A policy cannot be owned jointly by two or more employees Every policy must be owned by some employee Dependents is a weak entity, and uniquely identified by taking p in conjunction with policyid of a policy entity ER diagram is inaccurate What are the additional constraints in the 2nd diagram? Employees Employees Bad design ssn ssn Covers Policies policyid cost p age Dependents p age Dependents Better design Purchaser Beneficiary Policies policyid cost

Binary vs. Ternary Relationship (Contd.) 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?

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

Summary of Conceptual Design Several kinds of integrity constraints can be expressed in the ER model: key constraints participation constraints 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

Summary of Conceptual Design ER design is subjective There are often many ways (alternatives) to model a given scenario Common choices include: Entity vs. attribute, Entity vs. relationship Binary or n-ary relationship Whether or not to use ISA hierarchies / aggregation To ensuring good database design: Resulting relational schema should be analyzed and refined further FD information and normalization techniques are especially useful

ER Modeling Question - 0 Should explain the following terms: entity, relationship, entity set, relationship set, attribute, domain, one-to-many relationship, many-to-many relationship, participation constraint, overlap constraint, covering constraint, weak entity set, aggregation, role indicator.

Attribute - a property or description of an entity. A toy department employee entity could have attributes describing the employee s, salary, and years of service. Domain - a set of possible values for an attribute. Entity - an object in the real world that is distinguishable from other objects such as the green dragon toy. Entity set - a collection of similar entities such as all of the toys in the toy department. Relationship - an association among two or more entities. Relationship set - a collection of similar relationships One-to-many relationship - a key constraint that indicates that one entity can be associated with many of another entity. An example of a one-to-many relationship is when an employee can work for only one department, and a department can have many employees. Many-to-many relationship - a key constraint that indicates that many of one entity can be associated with many of another entity. An example of a many-to-many relationship is employees and their hobbies: a person can have many different hobbies, and many people can have the same hobby.

Participation constraint - a participation constraint determines whether relationships must involve certain entities An example is if every department entity has a manager entity Participation constraints can either be total or partial A total participation constraint says that every department has a manager A partial participation constraint says that every employee does not have to be a manager Overlap constraint - within an ISA hierarchy, an overlap constraint determines whether or not two subclasses can contain the same entity Covering constraint - within an ISA hierarchy, a covering constraint determines where the entities in the subclasses collectively include all entities in the superclass For example, with an Employees entity set with subclasses HourlyEmployee and SalaryEmployee, does every Employee entity necessarily have to be within either HourlyEmployee or SalaryEmployee? Weak entity set - an entity that cannot be identified uniquely without considering some primary key attributes of another identifying owner entity An example is including Dependent information for employees for insurance purposes Aggregation - a feature of the entity relationship model that allows a relationship set to participate in another relationship set. This is indicated on an ER diagram by drawing a dashed box around the aggregation Role indicator - If an entity set plays more than one role, role indicators describe the different purpose in the relationship An example is a single Employee entity set with a relation Reports-To that relates supervisors and subordinates

ER Modeling Example - 1 A university database contains information about professors (identified by social security number, or SSN) and courses (identified by courseid) Professors teach courses; each of the following situations concerns the Teaches relationship set. For each situation, draw an ER diagram that describes it (assuming no further constraints hold)

ER Modeling Example - 1 Professors can teach the same course in several semesters, and each offering must be recorded Professors can teach the same course in several semesters, and only the most recent such offering needs to be recorded. (Assume this condition applies in all subsequent questions.) Every professor must teach some course

ER Modeling Example - 1 Every professor teaches exactly one course (no more, no less) Every professor teaches exactly one course (no more, no less), and every course must be taught by some professor Now suppose that certain courses can be taught by a team of professors jointly, but it is possible that no one professor in a team can teach the course. Model this situation, introducing additional entity sets and relationship sets if necessary

Different ER Modeling Notations

Chen vs. Crow s Foot Notation

Crow s Foot Notation