Chaps7&8-1 CSE 4701 Chapters 7 & 8 6e - 3 & 4 5e: The ER Model Prof. Steven A. Demurjian, Sr. Computer Science & Engineering Department The University of Connecticut 191 Auditorium Road, Box U-155 Storrs, CT 06269-3155 [email protected]http://www.engr.uconn.edu/~steve (860) 486 - 4818 A large portion of these slides have been adapted from the AWL web site for the textbook. The remainder of these slides are being used with the permission of Dr. Ling Lui, Associate Professor, College of Computing, Georgia Tech.
112
Embed
Chaps7&8-1 CSE 4701 Chapters 7 & 8 6e - 3 & 4 5e: The ER Model Prof. Steven A. Demurjian, Sr. Computer Science & Engineering Department The University.
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Chaps7&8-1
CSE 4701
Chapters 7 & 8 6e - 3 & 4 5e: The ER Model
Prof. Steven A. Demurjian, Sr. Computer Science & Engineering Department
The University of Connecticut191 Auditorium Road, Box U-155
A large portion of these slides have been adapted from the AWL web site for the textbook.
The remainder of these slides are being used with the permission of Dr. Ling Lui, Associate Professor, College of Computing, Georgia Tech.
Chaps7&8-2
CSE 4701
Information System Design
Chaps7&8-3
CSE 4701
Data vs. Information
Chaps7&8-4
CSE 4701
The ER Model and its extensions ER Diagrams- Notation Example Database Application (COMPANY) ER Model Concepts
Entities and Attributes Entity Types, Value Sets, and Key Attributes Relationships and Relationship Types Weak Entity Types Roles and Attributes in Relationship Types
Relationships of Higher Degree Extended Entity-Relationship (EER) Model Notation is based on :
R. Elmasri and S.B. Navathe, “ Fundamentals of Database Systems,” Ed. 6., Addison Wesley, 2000, Chapters 7 & 8.
Chaps7&8-5
CSE 4701
Summary of ER-Diagram NotationMeaning
ENTITY TYPE
WEAK ENTITY TYPE
RELATIONSHIP TYPE
IDENTIFYING RELATIONSHIP TYPE
ATTRIBUTE
KEY ATTRIBUTE
MULTIVALUED ATTRIBUTE
COMPOSITE ATTRIBUTE
DERIVED ATTRIBUTE
TOTAL PARTICIPATION OF E2 IN R
CARDINALITY RATIO 1:N FOR E1:E2 IN R
STRUCTURAL CONSTRAINT (min, max) ON PARTICIPATION OF E IN R
Symbol
E1 R E2
E1 RN E2
R(min,max)
E
N
Chaps7&8-6
CSE 4701
Example COMPANY Database Requirements of the Company (Oversimplified for
Illustrative Purposes) Company is Organized into Departments
Each Department has a Name, Number and an Employee Who Manages the Department
We Track of the Start Date of the Department Manager Each Department Controls a Number of Projects
Each Project has a Name, Number and is Located at a Single Location
Chaps7&8-7
CSE 4701
Example COMPANY Database (Cont.) Store Each Employee’s Social Security Number,
Address, Salary, Sex, and Birthdate Each Employee Works for One Department but May
Work on Several Projects We Track of the Number of Hours Per Week that an
Employee Currently Works on Each Project We Track of the Direct Supervisor of Each Employee
Each Employee May have a Number of Dependents For Each Dependent, We Track of their Name, Sex,
Birthdate, and Relationship to Employee
Chaps7&8-8
CSE 4701
ER Diagram for the Company Database
Chaps7&8-9
CSE 4701
ER Model Concepts: Entities and Attributes Entities - Specific Objects or Things in the Mini-world
that are Represented in the Database EMPLOYEE John Smith Research DEPARTMENT Productx PROJECT
Attributes are Properties Used to Describe an Entitye.g., an EMPLOYEE Entity may have a Name, SSN, Address, Sex, Birthdate
A Specific Entity (Instance) has a Value for Each of its Attributes Specific Employee Entity May Have Name=‘John
What Does Works_On Represent? Realization of a Table That Links Employee and
Project Has Attributes Duration & Responsibility
Works_On(EmpNo, ProjNo, Duration, Resp)
Chaps7&8-19
CSE 4701
Relationships and Relationship Types Degree of a Relationship Type is the Number of
Participating Entity Types Both MANAGES and WORKS_ON are Binary
Relationships What is a possible Ternary Relationship?
More Than One Relationship Type Can Exist With the Same Participating Entity Types EMPOYEE MANAGES DEPARTMENT and
EMPOYEE WORKS_FOR DEPARTMENT Two Distinct Relationships Between EMPLOYEE
and DEPARTMENT Entity Types Relationships are Directional
SUPPLIES: SUPPLIER to PARTS SUPPLIERS: PARTS to SUPPLIER
Chaps7&8-20
CSE 4701
E-R Diagrams
EMPLOYEE PROJECT
Responsibility
Duration
Budget
ProjectName
Project NoEmployee No EmployeeName
SalaryTitle
WORKS ON
Address
CityApt. #
Street #
NoEmp
Location
Chaps7&8-21
CSE 4701
Weak Entity Types Entity that Does Not have a Key Attribute Weak Entity Must Participate in an Identifying
Relationship Type with an Owner or Identifying Entity Type
Entities are Identified by the Combination of: A Partial Key of the Weak Entity Type Particular Entity they Are Related to in the
Identifying Entity Type Example:
A DEPENDENT Entity is Identified by Dependent’s First Name and Birthdate, and the EMPLOYEE That the Dependent is Related to
DEPENDENT is a Weak Entity Type With EMPLOYEE as its Identifying Entity Type Via the Identifying Relationship Type DEPENDENT_OF
Chaps7&8-22
CSE 4701
ER Model and Data Abstraction Abstraction Classification
Aggregation
Identification Generalization
ER Model Concept Entity Type - a Grouping of Member Entities Relationship Type - a Grouping of Member
Relationships Relationship Type is an Aggregation of (Over) Its
Participating Entity Types Weak Entity Type and Attribute Key EER Diagram … TBD
Chaps7&8-23
CSE 4701
Constraints on Aggregation Cardinality Constraints on Relationship Types
AKA Ratio Constraints Maximum Cardinality
One-to-One One-to-Many Many-to-Many
Minimum Cardinality (AKA Participation or Existence Dependency Constraints) Zero (Optional Participation, Not Existence-Dependent) One or More (Mandatory, Existence-Dependent)
Chaps7&8-24
CSE 4701
e1
e2
e3
e4
e5
e6
e7
EMPLOYEE
r1
r2
r3
r4
r5
r6
r7
WORKS_FOR
d1
d2
d3
DEPARTMENT
One-to-many(1:N) or Many-to-one (N:1)One Dept Contains Many Employees (1:N)Many Employees Works for One Dept (N:1)
Chaps7&8-25
CSE 4701
e1
e2
e3
e4
e5
e6
e7
r1
r2
r3
r4
r5
r6
r7
d1
d2
d3
r8
r9
MANY-TO-MANY(M:N)
Chaps7&8-26
CSE 4701
One-to-One WORKS_ON Relationship
WORKS_ONRelationship
Instances
EMPLOYEE Set PROJECT Set
One Employee Works on One Project (1:1)
Chaps7&8-27
CSE 4701
EMPLOYEE PROJECT
Responsibility
Duration
Budget
ProjectName
Project NoEmployee No EmployeeName
SalaryTitle
WORKS ON1 1
One-to-One Relationship Each Instance of One Entity Class E1 Can Be
Associated with Exactly One Instance of Another Entity Class E2 and Vice Versa.
Example: Each Employee Can Work in Exactly One Project
and Each Project Employs Exactly One Employee
Chaps7&8-28
CSE 4701
One-to-Many WORKS_ON Relationship
Chaps7&8-29
CSE 4701
EMPLOYEE PROJECT
Responsibility
Duration
Budget
ProjectName
Project NoEmployee No EmployeeName
SalaryTitle
WORKS ON1N
Many-to-One Relationship Each Instance of One Entity Class E1 can be
Associated with Zero or More Instances of Another Entity Class E2, but Each Instance of E2 can be Associated With at Most 1 Instance of E1
Example : Each Employee Can Work in Exactly One Project
Each Project Can Employ Many Engineers
Chaps7&8-30
CSE 4701
Many-to-Many WORKS_ON Relationship
Chaps7&8-31
CSE 4701
EMPLOYEE PROJECT
Responsibility
Duration
Budget
ProjectName
Project NoEmployee No EmployeeName
SalaryTitle
WORKS ONN M
Many-to-Many Relationship Each Instance of One Entity Class Can Be Associated
with Many Instances of Another Entity Class, and vice versa
Example: Each Employee Can Work in Many Projects
Each Project Can Employ Many Employees
Chaps7&8-32
CSE 4701
Structural Constraints Structural Constraints on a Relationship are One Way
to Express the Semantics of a Relationship Cardinality Ratio (of a Binary Relationship):
1:1, 1:N, N:1, or M:N Shown by Placing Apropos Number on the Link
Participation Constraint (on Each Entity Type): Total (Called Existence Dependency) or Partial Total Shown By Double Lining The Link
NOTE: Easy to Specify for Binary Relationship Types Do Not Be Misled by Obscure Notations to
Specify Above Constraints for Higher Order Relationships
Chaps7&8-33
CSE 4701
Alternative (min, max) Notation Alternative (Min, Max) Notation for Relationship
Structural Constraints Introduces Limits Specified on Each Participation of an Entity Type E in
a Relationship Type R Specifies That Each Entity E in Participates in at Least
Min and at Most Max Relationship Instances in R Default (no Constraint): Min = 0, Max = n Must Have Min max, Min 0, Max 1
Derived From the Knowledge of Mini-World Constraints
A Full Time Student for the Registered Relationship Must Registered for at Least 3 courses and at most 6
Chaps7&8-34
CSE 4701
Examples: Alternative (min, max) Notation A Department has Exactly One Manager and an
Employee Can Manage at most One Department. Specify (0, 1) for Participation of EMPLOYEE in
MANAGES – Not every employee manager (0) Specify (1, 1) for Participation of DEPARTMENT
in MANAGES – Each dept needs a manger An Employee can Work for Exactly One Department
but a Dept. can have any Number of Employees Specify (1, 1) for Participation of EMPLOYEE in
WORKS_FOR Specify (0, n) for Participation of DEPARTMENT
in WORKS_FOR
Chaps7&8-35
CSE 4701
Examples: Alternative (min, max) Notation
What does it mean to put m:n:p on the three arms of the relationship? It is essentially meaningless. The (min,max) notation “looking away” from the entity is the best to use.
(1,1)(0,1)
(1,N)(1,1)
Chaps7&8-36
CSE 4701
Relationships of Higher Degree Relationship Types of Degree 2 Are Called Binary Relationship Types of Degree 3 Are Called Ternary
There is a Concrete Relationship Instance that Involves all Three Entity Types
These are Not Separate Relationships! Relationship Types of Degree N Are Called N-ary
Again - Concrete n-Participation Relationship In General, an N-ary Relationship is Not Equivalent to
N Binary Relationships Rather - it is more Analogous to the Grouping of
Ternary Relationships Alternatively, Could Use Weak Entity (Supply) and
Three Identifying Relationships (SS, SPJ, SP) Generate one Relational Table Supply that Links
Supplier, Project, and Part by SS, SPJ, SP, Respect.
Chaps7&8-40
CSE 4701
Ternary vs. Binary Relationships
Chaps7&8-41
CSE 4701
Constraints on Higher Order Relationships
What does it mean to put m:n:p on the three arms of the relationship ?
How do you set up the instance level diagram between actual suppliers, projects, and parts?
mn
p
Chaps7&8-42
CSE 4701
Higher Order (min,max) Examples
A Teacher can offer min 1 and max 2 OfferingsA Course may have 1 to 3 OfferingsA Student may enroll in from 1 to 5 Offerings
(1,5)
(1,3)(1,2)
What Does Each Mean?
Chaps7&8-43
CSE 4701
s1
s2
SUPPLIER
p1
p2
p3
PART
r1
r2
r3
r4
r5
r6
r7
SUPPLY
j1
j2
j3
PROJECT
Ternary Relationships - Instances
Chaps7&8-44
CSE 4701
Modified Earlier Example
Chaps7&8-45
CSE 4701
Another ER Diagram - Bank Example
Chaps7&8-46
CSE 4701
In Class Exercise Patients (name, address, SSN, etc.), Physicians (name,
specialty, DEA#, etc.) , and Drug Companies (name, phone number, web site)
Drug (name, price, status (generic, brand), drug companies that sell the drug, etc.)
Each patient has a primary physician, a collection of physicians that can prescribe them drugs
Physician’s prescribe, can prescribe multiple drugs per patient to multiple patients
Physicians can prescribe the same or different drugs to the same or different patient
Prescription has a date, refills, DEA#, dosage (assume milligrams), pattern (1perday, 2perday, etc.), and fill requirement (brand or generic)
ABC Pharmacy has Contacts with many Companies with Start and End dates, QTY, etc.
What would the ER Diagram Look Like?
Chaps7&8-47
CSE 4701
Starting the Design What are the Entities?
What are the Relationships?
Patient, Physician, Drug Company, Drug
Patient has one Primary PhysicianEach Physician has Multiple Patients
Drug Company has Purchasing Contract on DrugsDrug Company Sells Multiple DrugsDrugs Sold by Multiple Companies
Physician Prescribes Multiple Drugs per PatientPatient has Multiple Drug PrescriptionsPhysician Prescribes to Multiple PatientsPatient gets Prescriptions from Multiple Physicians
Chaps7&8-48
CSE 4701
One Solution – Where is ABC?
Phone#
Patient
Drug
Physician
name
address email
SSN
status
price
name
expiration
name
email
address
specialtyPrimary
N 1
DEA#
Prescribes
refills N
N
dosage
dateFill
requirementpattern
Sold By
Purchasing Contract
start_date end_date
Chaps7&8-49
CSE 4701
ER Data Modeling Tools Many Popular Existing Tools Advantages:
Documentation of Application Requirements User Interface - Mostly Graphics Editor Support
Disadvantages: Poor Diagramming
To Avoid Layout Algorithms and Aesthetics of Diagrams, They Prefer Boxes and Lines and Typically Only Represent (Primary-foreign Key) Relationships Among Resulting Tables
Lack of Built-in Methodology Support Poor Tradeoff Analysis/User-driven Design Preferences Poor Design Verification/Suggestions for Improvement
Chaps7&8-50
CSE 4701
Data modeling, design and reengineering Visual Basic and Visual C++
Visio EnterpriseVisio
Data modeling, business logic modelingEnterprise Application SuiteSybase
Conceptual modeling up to code maintenanceXcaseResolution Ltd.
Mapping from O-O to relational modelRW MetroRogue Ware
Modeling in UML and generation in C++ and JAVATogether has support for limited ER Design
Rational RoseTogether Control Center
RationalTogether/Borland
Mapping from O-O to relational modelPwertierPersistence Inc.
Data, process, and business component modelingPlatinum Enterprice Modeling Suite: Erwin, BPWin, Paradigm Plus
Platinum Technology
Data modeling, object modeling, process modeling, structured analysis/design
System Architect 2001Popkin Software
Database modeling, application developmentDeveloper 2000 and Designer 2000
Oracle
Database administration and space and security management
DB Artisan
Database Modeling in ER and IDEF1XER StudioEmbarcadero Technologies
FUNCTIONALITYTOOLCOMPANY
Tools Circa 2007 ER Modeling Tools
OutDated
Chaps7&8-51
CSE 4701
Current Tools Quest Software's Toad Data Modeler for SQL
Server 3.5, Xpert Edition Altova's DatabaseSpy 2011, Enterprise Edition Datanamic Solutions' DeZign for Databases 6.2,
ER Design Topics Clear Distinction of the Usage of Entity and Attribute,
As Well As Entity and Relationship Clear Understanding of Complications in ER
Modeling Recursive Relationship Multiple Relationships Between Two Entity Types Participation Constraints (Existence Constraints) Strong and Weak Entities Relationships Among More than two Entity Types Connection Traps Simplification Techniques
Chaps7&8-53
CSE 4701
Interactions of Entity/Relationships Types In a Recursive Relationship two Entities of the Same
Entity Type Are Related SUPERVISION Relationship Type Relates One
EMPLOYEE (in the Role of Supervisee) to Another EMPLOYEE (in the Role of Supervisor)
Similarly, the Same Entity Type May Play Different Roles in Different Relationships Employee Plays the Role
A Relationship Type Can Have Attributes HoursPerWeek of WORKS_ON Value for Relationship Instance Describes # of
hrs/week an EMPLOYEE Works on a PROJECT
Chaps7&8-54
CSE 4701
Recursive Relationships
EMPLOYEE
MANAGES
1 N
Manager Subordinate
PART
CONTAIN
M N
Made-up of Consists of
Chaps7&8-55
CSE 4701
Understanding Multiple Relationships
EMPLOYEE PROJECT
ResponsibilityDuration
Budget
ProjectName
Project NoEmployee No EmployeeName
SalaryTitle
WORKS ON
N M
MANAGES
1 1
Chaps7&8-56
CSE 4701
Strong and Weak Entity Types Strong Entities:
Instances of the Entity Class Can Exist on their Own, Without Participating in any Relationship
Non-obligatory Membership Weak Entities:
Each Instance of the Entity Class Has to Participate in a Relationship in Order to Exist
Keys Are Imported From Dependent Entity
Also Called Obligatory Membership
Special Type of Total Participation
What Does Diagram Represent?
Course
number-of- sessions
instructorsession#
1
n
C-S
Session
Chaps7&8-57
CSE 4701
Higher Order Relationships
SUPPLIERPROJECT
DateAmount
Budget
ProjectName
Project NoSupplier No Supplier
Name
LocationCredit SUPPLY
NM
PART
LPart No
PartName
QTY
WGT
Three way relationships
Chaps7&8-58
CSE 4701
Connection Traps A N-ary Relationship cannot be Replaced by
a Number of Binary Relationships (Loss of Information)
So, (a) < > (b)! There are no Easy Solutions to this
Problem! Equivalent Relational Tables Different
(previous)
Chaps7&8-59
CSE 4701
Connection Traps - Example 2 Example: Each Division Has Multiple Depts. and Many
Employees , Each Employee Works for One Dept. in a Div., and Each Dept. is Within a Div. and Has Many Employees
Be Careful in Defining and Interpreting Relationships For Example, Consider the Following Diagram
Can We Find, for Any Given Emp., Which Dept. He is in? Conversely, Can We Find, for a Given Dept., Which Emps.
are in that Dept.?
DIVISION
DEPARTMENT EMPLOYEE
1
N
1
N
INCLUDESDEPT
INCLUDESEMP
Chaps7&8-60
CSE 4701
Example 2 - One Solution Change the Relationship Definition Division to Dept. and Dept. to Employee Replaces
Division to Dept. and Division to Employee
DIVISION
DEPARTMENT
EMPLOYEE
1
N 1
N
INCLUDESDEPT
INCLUDESEMP
Chaps7&8-61
CSE 4701
Many-to-Many Simplification Technique Cannot do by Simple Creation of two 1:N
Relationships Between the Two Entity Classes N:M Relationship Does Not Indicate a Dependence
Between Instances of the Two Entity Classes 1:N Relationship Forces a Dependency
Consider N:M Between EMPLOYEE and PROJECTN M
EMPLOYEE PROJECTWORKS ON
EMPLOYEE PROJECT
WORKS ON N
M EMPLOYS
1
1
WRONG
Chaps7&8-62
CSE 4701
Many-to-Many Simplification Technique Treat the Relationship as an Entity Class Define Suitable Relationships Among Three Entities This Simplification is not Necessary for Mapping into
the Relational Model, but is Important for Mapping into Other Models (Relational/Implementation)
EMPLOYEE PROJECTWORKS ONN M
EMPLOYEE PROJECT
EMP--EMP1
M
EMP--PROJ
EMPLOYMENT M
1
Chaps7&8-63
CSE 4701
What are Problems with ER Notation? Historically, ER Model 1st Proposed in 1976
P. Chen, ''The Entity-Relationship Model - Toward a Unified View of Data,'' ACM Trans. on Database Systems, Vol. 1, No. 1, March 1976.
However, ER Model in this Original Form Did Not Support the Generalization Abstraction (Inheritance)
In Databases, Inheritance 1st Proposed in 1977 J. Smith and D. Smith, ''Database Abstractions:
Aggregation and Generalization,'' ACM Trans. on Database Systems, Vol. 2, No. 2, June 1977.
Thus, Extended ER Evolved through 1980s with the Focus on “Semantic Data Models”
M. Hammer and D. McLeod, ''Database Descriptions with SDM: A Semantic Data Model,'' ACM Trans. on Database Systems, Vol. 6, No. 3, Sept. 1981.
Chaps7&8-64
CSE 4701
Enhanced ER Model Object-Oriented Extensions to E-R Model EER Concepts
Specialization Attribute Inheritance Generalization Subclasses Superclasses Constraints on Specialization and Generalization Categorization
Chaps7&8-65
CSE 4701
Specialization/Attribute Inheritance An Entity Type E1 is a Specialization of
another Entity Type E2 if E1 has the Same Properties of E2 and Perhaps Even More.
E1 IS-A E2
MANAGER
EMPLOYEE
EMPLOYEE
Employee No EmployeeName
Salary
Title Address
MANAGER
Employee No EmployeeName
Salary
Title Address
Expense Act. Condo
Chaps7&8-66
CSE 4701
Generalization Abstracting the Common Properties of Two
or More Entities to Produce a “Higher-level” Entity
Use-Case Diagrams One of the Key Diagrams Used in Conjunction with DB Design Interaction of Users with System Components Actors – Can Transition to Users/Privileges Against DB
External Entity that Interacts with Software Promote Simulation of Events Can be People, Classes, Software Tools, etc.
Use-Case Diagram Graph of Actors and Set of Use Cases Enclosed by System
(High-Level) or Class Boundary Focus on What Actions, Methods, Functions, etc. are
Utilized by Which Actors Black Box View of System Components Derived via User Interviews
Chaps7&8-91
CSE 4701
Actors Generalization from Child to Parent Association to a Use Case
Use-Cases Generalization
Child Use Case X to a Parent UC Y means that X inherits Behaviors/Meanings of Y
<<Include>> Base UC C to Included UC D means that C
contains the Behaviors defined in D <<Extend>>
From Extending UC E to Base UC F means that F Augmented with Behaviors of E
Include/Extend – Relationships Among Use Cases
Use-Case Relationships
Chaps7&8-92
CSE 4701
Supermarket Example
HTSS
Scan Items
Ring Order
Buy Items CustomerCashier
Catalog
Check Status
Place Order
Fill Order
Estb. Credit
Customer
Sales Person
Supervisor
HTSS: System View
Catalog: Class View
Chaps7&8-93
CSE 4701
Supermarket Example
Chaps7&8-94
CSE 4701
Use Case Scenario Write Rx Physician Decides to
Prescribe Medication for Patient
Physician Specifies Drug Info: Medication Name, Dosage Amount, Number Doses & Refills
Computer Cross-Checks for Conflict Between Medication and Current Medications/Medical History
Prescription Forwarded Electronically to Pharmacy or Else Printed for Patient
+
Chaps7&8-95
CSE 4701
Health Care Example
Chaps7&8-96
CSE 4701
Use-Case Diagrams
Chaps7&8-97
CSE 4701
Another Important Diagram to DB Design Need to Synchronize ER Entities and App Classes
Utilized for Static Structure of Conceptual Model Class Diagram Describes
Types of Objects in Application Static Relationships Among Objects Temporal Information Not Supported
Class Diagrams Contain Classes: Objects, Attributes, and Operations Packages: Groupings of Classes Subsystems: Grouping of Classes/Packages
Main Concepts: Class, Association, Generalization, Dependency, Realization, Interface
Class Diagram
Chaps7&8-98
CSE 4701
A Class is a Description of Set of Objects that Share the Same Attributes, Operations, Methods, Relationships, and Semantics
Classes are Graphically Represented as Boxes with Compartments for Class Name, Private Attributes, and Public