PowerPoint Slides

advertisement
Self-paced Learning
and On-line Teaching of
Entity-Relationship Modeling
Peter Y. Wu
Jeanne M. Baugh
Valerie J. Harvey
(c) Robert Morris University 2006
A plan to teach ER Modeling
 Part of an undergraduate Database course
 IS 2002 Model Curriculum requirements
 6 weeks out of 15 – for a 3 credits course
 Designed for flexibility to cater to students
•
•
minimize need for face-to-face contact
facilitate for self-study and on-line learning
 For self-paced learning and on-line teaching
 Rely more on the students’ self-discipline
Nov 2, 2006
The (15 weeks) Schedule
Week(s)
Topic
1 to 6 Relational Data Model and Use of
SQL
7 and 8 Normal Forms and Normalization
(for design evaluation)
9 to 14 Entity-Relationship Modeling and
database design
15 Database Systems: administration
and management
Nov 2, 2006
A plan to teach ER Modeling
 For 6 weeks … (out of the 15-weeks course)
 The plan covers:




Fundamentals of Entity-Relationship Modeling
Application to the design of Relational Schema
Extended ER Modeling with Specialization
Optional alternative notations:



Nov 2, 2006
Bachman
UML
(automated tools) … to be added
19 Modules for ER Modeling
0
Introduction to ER modeling
1
2
Entities and Attributes
3
4
5
Key and Key Attributes
6
Relationship and
Relationship Instances
7
8
Types of Attributes
Tables for Entity Sets
The Index Card Analogy
Participation Constraint
Cardinality Constraint
Rules and Tips
9NovDesign
2, 2006
10
11
Tables for Relationship Sets
12
13
14
15
Tables for Weak Entity Sets
16
17
18
(min,max) Structural Constraint
Weak Entities and
Dependency Relationship
Creating Entity Sets in Design
Specialization and Generalization
Tables for Extended ER Model
Bachman Notation
ER Diagram using UML
M0: Introduction to ER Modeling
ER Modeling:
19 Modules
M1: Entity and Attributes
M2: Types of Attributes
M3: Key and Key Attributes
Dependency Graph
M4:Tables for Entity Sets
M5: Index Card Analogy
M6: Relationship and Relationship Instances
M7: Participation Constraint
M8: Cardinality Constraint
M9: Design Rules
M16: (min,max) Notation
M10:Tables for Relationship Sets
M11:Weak Entities
M17: Bachman Notation
optional
M12: Tables for Weak Entity Sets
M18: ER Diagram in UML
optional
M13: Creating Entity Sets
M14: Specialization / Generalization
M15: Tables for Extended ER Model
19 Modules for ER Modeling
0
Introduction to ER modeling
1
2
Entities and Attributes
3
4
5
Key and Key Attributes
6
Relationship and
Relationship Instances
7
8
Types of Attributes
Tables for Entity Sets
The Index Card Analogy
Participation Constraint
Cardinality Constraint
Rules and Tips
9NovDesign
2, 2006
10
11
Tables for Relationship Sets
12
13
14
15
Tables for Weak Entity Sets
16
17
18
(min,max) Structural Constraint
Weak Entities and
Dependency Relationship
Creating Entity Sets in Design
Specialization and Generalization
Tables for Extended ER Model
Bachman Notation
ER Diagram using UML
Module 0: Intro to ER modeling
1. Tool for database system analysis and
design.
2. Simple case study as an example.
3. ER model captures the way business works
with data.
4. ER diagram expresses the model, i.e., the
schema.
Nov 2, 2006
Entity-Relationship Model
Briefly introduced…
 Entity – thing
 Relationship – nature of association between
things (entities)
 Entity-Relationship Modeling – a way to
model the real world, as things, and how the
things are associated together.
 Entity-Relationship Diagram – we present our
model graphically.
Entity-Relationship Model
 Entity – a specific thing, physical or conceptual.
Example: the sun, the number one, the car
model Mustang, the man Adam.
 Attributes and Values – to model an entity by its
properties (e.g. color: red)
 Relationship – the way specific things are
associated in the nature of a relationship.
Example: Adam and Eve as husband and wife.
The association of related entities together
constitute a relationship instance.
Entity-Relationship Diagram
Example… (Info System for the university registrar)
 There are these entities: courses and instructors.
 Each instructor has a name and a phone number.
 Each course has course number and title.
 Instructors teach courses…
instructor
name
phone
teaches
course
number
title
Illustration: the data …
 Instructor P. Wu, phone x9420, teaches the course
IS4240, Database Management System.
 Instructor P. Laverty, phone x9429, teaches the course
IS4244, Document Processing.
 ...
name: P Laverty
phone: x9429
name: P. Wu
phone: x9420
number: 4240
title: DB Mgt Sys
number: 4244
title: Doc Proc
name: …
phone: xxxxx
number: 4249
title: E-Business
instructors
teaches
courses
Schema: conceptual to relational
instructor
teaches
course
name
number
title
phone
INSTRUCTOR
Name
Phone
TEACHES
Name
Number
COURSE
Number
Title
Module 1: Entities and Attributes
1. Modeling things as entities and their
attributes.
2. Attribute names and attribute values.
3. Entity as something specific, physical or
conceptual.
4. Entity, entity type, and entity set.
Nov 2, 2006
Module 2: Types of Attributes
1. Simple and composite attributes
2. Stored and derived attributes
3. Single and multiple valued attributes
4. Optional attributes
Nov 2, 2006
Module 3: Key and Key Attributes
1. The uniqueness constraint in ER modeling.
2. Key as a collection of attributes
3. Key, super key, and candidate key
4. Different candidate keys for the same entity
set.
Nov 2, 2006
Module 4: Tables for Entity Sets
1. Relational table for an entity set.
2. Primary key and secondary keys.
3. Optional attribute and column allowing null.
4. Extra table for multi-valued attribute.
Nov 2, 2006
Module 5: The Index Card Analogy
1. Entity set as a deck of index cards.
2. Entity set name and attribute names are
printed on each card.
3. A card with attribute values filled in
represents the entity.
Nov 2, 2006
Example… Entity Set in ER Model
BOOK
Database System
by G. Riccardi
Question: are we talking
about a book (published)
or a copy (printed) ?
Example… Entity Set with Attributes
course
course
title: DBMS
number: 4240
course
title: E-Business
title: Doc Proc number: 4249
number: 4244
… think of each entity set as a deck of cards.
Each card is labeled with entity type, and the same
attributes, being of the same type.
Each card has its own specific values for each of the
attributes, representing a specific entity.
Relational Table from Entity Set
Name
Student
Major
student
student
name: John Doe
major: Info Sci
student
name: Pat Wong
name: Lily Smithmajor: Comp Sci
major: Psychology
Student
Note that the ER Model conveys the
conceptual structure of information,
not the data values.
Name
Major
John Doe
Info Sci
Lily Smith
Psychology
Pat Wong
Comp Sci
...
...
Module 6: Relationship and
Relationship Instances
1. Binary relationship in ER modeling.
2. Relationship set, relationship instance.
3. Relationship attributes.
4. Relationship has NO key attribute. Why?
Nov 2, 2006
Relationship Instances…
course
course
title: E-Business
title: DB Mgt Sys
number: 4249
number: 4240
teaches
(P. Laverty, 4249)
teaches
(P.Wu, 4240)
teacher
teacher
name: P. Laverty
phone: x 9420
name: P.Wu
phone: x 9427
Relationship Set
Module 7: Participation Constraint
1. Total participation.
2. Partial participation.
Nov 2, 2006
Module 8: Cardinality Constraint
1. 1-to-1 cardinality ratio.
2. 1-to-many and many-to-1 cardinality ratios.
3. Many-to-many cardinality ratio.
4. Cardinality ratios working with participation
constraints.
5. Properly interpreting cardinality constraints.
Nov 2, 2006
Module 9: Design Rules and Tips
1. Two entity sets can connect only thru a
relationship.
2. Attribute value should never imply a
relationship between entities; relationship
should be explicit in the model.
3. Relationship should never connect with
another relationship; at least one of them
can be treated as an entity set.
Nov 2, 2006
Entity Sets
 Do NOT connect one Entity Set to another.
employee
X
office
Example: Explicit Relationship!
We should model relationship explicitly and avoid
using attributes to imply a relationship.
employee
X
name
office
e-mail
office
occupies
X
occupant
phone
room#
Example: Explicit Relationship.
So that we may also keep track of changes in the
near future within our database…
employee
occupies
office
phone
name
e-mail
effective
date
room#
Example: relationship or entity?
Men and Women members of a skating club are
going to pair up in a competition….
Man
pairs up
with
pair
number
Woman
Example: relationship or entity?
Each pair will compete and get rated by three
judges, each giving a score…
Judge
rates
score
Pair
Example: relationship to relationship?
 A relationship is the association of entities,
should not be that of other relationships!
Man
Judge
?
rates
Woman
pairs up
with
pair
number
score
Example: relationship to entities!
Man
Woman
Pair
pair
number
Judge
rates
score
Module 10: Tables for
Relationship Sets
1. Additional table is needed for M-to-M
2.
3.
4.
5.
relationship.
M-to-1 relationship: table at the “1” side may
be extended to carry information for the
relationship.
1-to-1 relationship: may extend either side,
or both sides.
Use of foreign keys in these tables.
Allowing null values for partial participation.
Nov 2, 2006
Module 11: Weak Entities and
Dependency Relationships
1. Entities dependent on its relationships for
identity.
2. Symbol for entity set and dependency
relationships.
3. When dependency relationship is 1-to-1…
4. The need for partial key when dependency
relationship is M-to-1.
Nov 2, 2006
Example: Weak Entity Set
 Consider modeling the information in a library. We
have the entity set Book for books…
title
Book
author
year
Call No
Example: Weak Entity Set
 Members of the library may borrow books: we have a
relationship between Book and Member…
Member
loan
Book
due date
PROBLEM!
• Can we have two different members borrowing the
same book? (More accurately stated: two different
copies of the same book?)
Example: Weak Entity Set
 The Book entity set: does each entity represent a
book? OR a copy of a book? Need copy number!
title
Book Copy
author
year
Call No + Copy No
Example: Weak Entity Set
 We need to deal with two different concepts in the
library: book, and copy of a book:
Book Copy
Book
title
title
author
author
call no
copy no
call no
Example: Weak Entity Set
 With both Book and Book Copy, we can properly
model the relationships with Member.
(0,*)
Member
(0,4)
reserves
(0,*)
Book
expected
date
borrows
(0,1)
due date
Book Copy
Example: Weak Entity Set
 We duplicate a good deal of information in the
entity sets: Book and Book Copy – the two
should be related! (implied relationship)
1
Book
title
N
copies
Book Copy
title
author
author
call no
copy no
call no
Example: Weak Entity Set
 We will allow a weak entity set for Book Copy, with
partial key copy no (underlined by dash), and a
dependency relationship copies to a strong entity set.
1
Book
N
copies
Book Copy
title
author
copy no
call no
Module 12: Tables for
Weak Entity Sets
1. Weak entity set translates into a table in the
same way (as strong entity set).
2. Key for the weak entity set table.
3. The need to combine with partial key.
4. Extending the table to take care of attributes
of the dependency relationship.
Nov 2, 2006
Module 13: Creating Entity Sets
in Design
1. Entity versus attribute: an attributive entity.
2. Entity versus relationship: an associative
weak entity.
3. Weak entity with multiple dependency
relationships.
Nov 2, 2006
Module 14: Specialization and
Generalization: Extended ER Modeling
1. Referring to a subset of an entity set:
2.
3.
4.
5.
specialization in Extended ER modeling.
Super class and sub-class, with inheritance.
Total and partial specialization.
Disjoint and overlap specialization.
Generalization in Extended ER modeling:
the reverse of specialization.
Nov 2, 2006
Module 15: Tables for
the Extended ER Model
1. Table for superclass – same as an entity set.
2. Table for subclass: keys inherited.
3. Foreign key in subclass tables.
4. Special cases when specialization is total
and disjoint (superclass table unnecessary).
Nov 2, 2006
Module 16: (min,max)
Structural Constraint
1. Definition of the (min,max) notation for
structural constraint.
2. Interpreting the (min,max) notation into
participation and cardinality constraints.
Nov 2, 2006
Module 17: Bachman Notation
1. Entity sets – no more ovals…attributes listed
inside the box (or use pop-up window in a
computerized tool).
2. No more diamonds; a line connecting two
boxes indicate relationship between two
entity sets.
3. Adornment for structural constraints.
4. Notes on associative and attributive entities.
Nov 2, 2006
Bachman’s Notation
Employee
is assigned to
Office
 Every employee is assigned to exactly one office
and every office is assigned one employee.
 One-to-One relationship with total participation at
both ends.
Bachman’s Notation
Cargo
Aircraft
serves
Distribution
Center
 Every cargo aircraft serves one or more
distribution centers and every center is served
exactly one aircraft.
 One-to-Many relationship with total
participation at both ends.
Bachman’s Notation
Systems
Analyst
is in charge of
Project
 An analyst may be in charge of many projects (or
may not be in charge of any) and every project has
exactly one systems analyst in charge.
 One-to-Many relationship with total participation at
one end (Project) and partial at the other (Analyst).
Bachman’s Notation
Machine
is undergoing
Scheduled
Maintenance
 A machine may or may not be undergoing scheduled
maintenance and every scheduled maintenance always
refers to exactly one machine.
 One-to-One relationship with total participation at one
end (Scheduled Maintenance) and partial at the other
(Machine).
Bachman’s Notation
Salesperson
is assigned to call on
Customer
 Every salesperson is assigned to call on one or
more customers, and every customer has one or
more salespersons assigned to call.
 Many-to-Many relationship with total
participation at both ends.
Bachman’s Notation
Home
Office
is permitted to
Employee
 Every home office is permitted to one or more
employees, and an employee may or may not
be permitted to a home office.
 One-to-Many relationship with total
participation at one end (Home Office) and
partial at the other end (Employee).
Bachman’s Notation
Partner participation is optional,
with at most one unit per partner: one-to-?
… (0,1).
Partner participation is mandatory,
with at most one unit per partner: one-to-?
… (1,1).
Partner participation is mandatory,
with possibly many units per partner: many-to-?
… (1,*).
Partner participation is optional,
with possibly many units per partner: many-to-?
… (0,*).
Module 18: ER Diagram in UML
1. Basic UML: classes and objects.
2. Public, private, and protected attributes.
3. Connection and multiplicities.
4. Broader software construction aspects of
UML.
Nov 2, 2006
19 Modules to teach ER modeling
 Small modules: complete and compact
 Specific learning objectives in each module
 Motivate self-study: perceiving progress…
 Minimize need for face-to-face contact hours
 Sequence: each builds on previous ones
 Exercise for each module re-enforces the
learning objectives thru practice.
 Suitable to delivery on-line.
Nov 2, 2006
Further Work …
 Compare student performance and attitude to
evaluate the effectiveness of the plan.
 The modules may constitute a stand-alone
tutorial on ER modeling.
 Try the experimental use of Intelligent
Tutoring System.
 Gather sufficient exercises and tests to
deliver the teaching on-line, for self-paced
studying.
Nov 2, 2006
Download