Er Diagram For Pine Valley Furniture Company
Er Diagram For Pine Valley Furniture Company
Er Diagram For Pine Valley Furniture Company
Conceptual Modeling
Entity Relationship Diagrams
Objectives
Definition of terms Importance of data modeling Write good names and definitions for entities, relationships, l ti hi and d attributes tt ib t Distinguish unary, binary, and ternary relationships Model different types of attributes attributes, entities entities, relationships, and cardinalities E R diagrams for common business situations Draw E-R Convert many-to-many relationships to associative entities Model time-dependent data using time stamps
2
Business Rules
Statements that define or constrain some aspect of the business Assert business structure Control/influence business behavior Are expressed in terms familiar to end users Govern how data are stored and handled. Our DB App will (hopefully) automate business rules
3
E/R Modeling
The E/R model is used p to construct a conceptual data model a representation of the structure and constraints of a database and is the technology independent.
E-R E R Modeling
An E-R model is based on: Entities Relationships between entities Attributes of entities and relationships E-R diagram ag graphical p representation p of an E-R model
Entity symbols
A special entity y that is also a relationship
Relationship degrees specify number of entity types involved
Attribute symbols
Relationship symbols
10
Entities
Things in the real world, physical or not: person, place object, place, object event, event concept
Entity Type
collection of entities that share properties or characteristics Entity type is always SINGULAR Student Represented by a rectangle
Entity Instance
each of the instances of an entity type
11
12
System user
Inappropriate pp p entities
Appropriate entities
13
Attributes
Attribute - p property p y or characteristic of an entity y type that is of interest to the organization. Classifications of attributes:
Required versus Optional Attributes Simple versus Composite Attribute Single-Valued versus Multi-valued Attribute Stored versus Derived Attributes Identifier Attributes
14
Figure 2-8 Entity with multivalued attribute (Skill) and derived attribute (Years Employed)
Multivalued an employee can have more than one skill
Identifiers (Keys) ( y)
Identifier (Key) - An attribute (or combination of attributes) ib ) that h uniquely i l id identifies ifi individual i di id l instances i of an entity type Simple Key versus Composite Key Candidate Key an attribute that could be a keysatisfies y the requirements q for being g a key y
16
18
Practice: Person
Produce an E-R diagram for the following situation: We have one entity, called Person, with the following attributes: tt ib t ID (the (th identifier); id tifi ) Name, N which hi h is i composed d of one or more given names and one or more family names; ; one or more aliases; ; an address (composed ( p of street, city, state, zip); date of birth; and age, which can be calculated from the date of birth.
19
Relationships p
Association between two or more entities Represented by connecting lines
20
b) Relationship instances
21
Relationships p
Degree Cardinality constraints
22
24
Interpreting Cardinalities
25
Interpreting Cardinalities
26
Cardinality Constraints
Cardinality y Constraints - the number of instances of one entity that can or must be associated with each instance of another th entity. tit Minimum Cardinality
If zero, then th optional ti l If one or more, then mandatory
Maximum Cardinality
The maximum number
27
Quick Check
So now you try it it. Add cardinality constraints to the following diagram
A person is national of zero or more countries A country has one or more people.
28
29
a) Mandatory cardinalities
A patient must have recorded at least one history history, and can have many
30
31
Maximum Cardinalities
Looking at the MAXIMUM cardinality on BOTH sides, , we classify y relationships p as:
1:1
1:M
M:N
32
Practice: Products
We have two kinds of entities: Products and Categories. g For each p product we keep p its id (identifier), name, price, wholesale price, and profit margin, which is calculated from the price and the wholesale h l l price. i For F each h category t we keep k its it id (identifier) and its name. Each product belongs to zero or more categories g and each category g y can have zero or more products.
33
Practice : CD
Let us model a CD with three entities: CD, PERSON and SONG SONG.
A CD has a number, which is its identifier, and a title A person has an ID and a name, divided into first, last A song has an ID, a title and a length We keep track of which person is a songs author. A person can author many songs and a song has exactly one author author. We keep track of which people perform on a CD. Zero or more people can perform on a CD, and people can perform on zero or more CDs. CD We keep track of which songs are included on a CD. One or more songs are included on a CD, and a song is included in zero or more CDs.
34
Weak entity
Dependent p on a strong g entity y cannot exist on its own Does not have a unique identifier (only a partial identifier) Partial identifier underlined with double-line E i box Entity b has h double d bl line li
Identifying relationship
links strong entities to weak entities
35
Strong entity
Weak entity
36
Strong entity
37
38
39
40
Figure 2-11a A binary relationship with an attribute Attribute on a relationship (Link Attribute/Associative)
Here, the date completed attribute pertains specifically to the employees employee s completion of a course courseit it is an attribute of the relationship
41
42
43
Homework Assignment g
Exercise #15(a,g), page #104 Exercise #17, #17 page #106 Exercise #25, page #107
44
Associative Entities
45
Associative Entities
One of the hardest concepts in E-R modeling An associative entity is a relationship transformed into an entity y represents p an Each instance of an associative entity instance of the relationship Needed to represent ternary relationships, and for cases when h we need d to t convert t a relationship l ti hi into i t an entity, to relate it to other entities.
46
S Suppose that h we also l want to record di information f i about b the h institutions issuing the certificates. HOW???
47
Associative entity is like a relationship with an attribute, but it is also considered to be an entity y in its own right g Note that the many-to-many cardinality between entities in Figure 2-11a 2 11a has been replaced by two one-to-many one to many relationships with the associative entity
48
Issues
50
Associative Entities
An entity - has attributes A relationship - links entities together When should a relationship with attributes instead be an associative entity y?
All relationships for the associative entity should be many The associative entity could have meaning independent of the other entities The associative entity preferably has a unique identifier, and should also have other attributes The associative entity may participate in other relationships other than the entities of the associated relationship
51
Homework Assignment g
Exercise #15(f), page #104
52
Ternary Relationships
53
Ternary Relationships
Relationships of degree 3 Associates three entities at the same time Can't we just live with binary relationships?
54
DEGREE
UNIVERSITY
DEGREE
60
Homework Assignment
Exercise #15(b) #15(b), page #104 Exercise #18, page 106
61
Unary Relationships
62
Unary Relationships
Relationships of degree 1 Also known as recursive relationships Two or more entities in the relationship are of the same type Example: we want to represent when an p y supervises p another employee. p y employee
63
Example: Supervises
Example: we want to represent when an employee supervises another employee. We W could ld start with i h something hi lik like this: hi
Supervises
SUPERVISOR
SUPERVISEE
64
Example: Supervises
But supervisors can have their own supervisors Both supervisor and supervisee are employees, so we need a recursive relationship relationship, with roles
Supervises Supervisee
EMPLOYEE
Supervisor
65
Example: Supervises
And And, of course course, add cardinalities Should always define roles even more important when cardinalities are different
Supervises
EMPLOYEE
V
Supervisor
Supervisee
c) Optional cardinalities
Ap person is married to at most one other person, or may not be married at all
68
ITEM
69
Fig. 2 2-13: 13: (b) Two ITEM bill bill-of-materials of materials instances
70
72
Homework Assignment
Exercise #10, ,p page g #103.
73
Attributes or Entity?
Sometimes y you will wonder whether to represent p data as an attribute or an entity. This is a common dilemma. Let us look at a few situations.
74
Figure 2-15a and 2-15b Multivalued attributes can be represented as relationships/Associative Entity
simple
composite
75
Attributes or Entity?
So when SHOULD an attribute be linked to an entity type via a relationship?
Attribute refers to a concept in the data model Multiple entity instances share the same attribute
76
Fig. 2-15: Using relationships and entities to link related attribute (c) ( ) Composite p attribute of data shared with other entity y types yp
77
78
??
Here, minimum cardinality constraint is 2, whats for?
80
Homework Assignment
Exercise #11, ,p page g #103 Exercise #15(d,i), page #105 Exercise #18, page #106 Exercise #20, page #106 Exercise #23, #23 page #107 Exercise #26, page #108
81
83
PRODUCT LINE
Product Product-Line P P B A
(out of $50,000)
PRODUCT
Placed
ORDER
84
85
86
87
88
Fig. 2-22: Microsoft Visio Notation for Pine Valley Furniture E-R diagram
Different modeling software tools may have different notation f th for the same constructs
89
90