Download presentation
Presentation is loading. Please wait.
Published byKathleen Manning Modified over 7 years ago
1
Chapter 2: Modeling Data in the Organization (THE BASIC ER-MODEL)
Modern Database Management 11th Edition, International Edition Jeffrey A. Hoffer, V. Ramesh, Heikki Topi © 2013 Pearson Education
2
Chapter Outline The E-R Model (E-R Diagram): An introduction
Modeling Business (事務、企業) Rules of Organizations Modeling Entities and Attributes Modeling Relationships E-R Modeling Example
3
Objectives Understand definitions of terms
Understand importance of data modeling Select good names and definitions for entities, relationships, and attributes Distinguish unary, binary, and ternary relationships Model different types of attributes, entities, relationships, and cardinalities Draw E-R diagrams for common business situations Convert many-to-many relationships to associative entities Model time-dependent data using time stamps
4
How to Select Good Data Name
Related to business, not technical, characteristics Meaningful and self-documenting Unique Readable Composed of words from an approved list Following a standard syntax
5
DATA NAMES and DEFINITIONS
Data objects must be named and defined Fundamental to understanding and modeling data A definition is an explanation of a term or fact Term : word or phrase with specific meaning Fact : association between two or more terms (A fact is used to relate terms) Guidelines for good data definition A concise description of essential data meaning Gathered in conjunction with systems requirements Accompanied by diagrams Achieved with a team agreement, and iteratively refined
6
CONSTRUCTS (組成) of E-R MODEL
Entities (實體): Entity instance (個例) : a person, place, object, event, or concept (often corresponds to a data row or a record in a table) Entity type (種類、型別) : a collection of entities (often corresponds to a table) Relationships (關係): Relationship instance : a link between entities (corresponds to a certain primary key-foreign key pair in related tables) Relationship type : a category of relationship (link between entity types) Attributes: Properties or characteristics of an entity or relationship type (often corresponds to a field or a column in a table) Student Table StdSSN StdLastName StdMajor StdClass WELLS IS FR NORBERT FIN JR KENDALL ACCT E-R diagram example 2
7
Sample E-R Diagram (Figure 2-1)
Each ITEM must be supplied by at least one SUPPLIERs. A SUPPLIER may supply many ITEMs. © 2013 Pearson Education Chapter 2 7 3
8
Basic E-R notation (Figure 2-2)
Entity symbols Attribute symbols A special entity that is also a relationship Relationship symbols Relationship degrees (度數) specify the number of entity types involved Relationship cardinalities (基數) specify how many entity instances of each entity type is allowed © 2013 Pearson Education Chapter 2 8 8
9
Business Rules (企業規則、事務規則)
Core concepts of an organization Statements that define or constrain some aspect of the business (企業、業務、事務) Derived from organizational policies, procedures, events, functions Assert business structure Control/influence business behavior Expressed in terms familiar to end users Can be automated through DBMS software Example : Each ITEM must be supplied by at least one SUPPLIERs. examples
10
A Good Business Rule Is:
Declarative (敘述性的) : what, not how Precise : clear, agreed-upon meaning Atomic : One statement, not several, for each rule. Consistent : internally and externally Expressible : structured, natural language Distinct (有區別的) : non-redundant Business-oriented : Understood by business people
11
Entities Entity Entity type Entity instance
A person, a place, an object, an event, or a concept in the user environment about which the organization wishes to maintain data Entity type A collection of entities that share common properties or characteristics Entity instance A single occurrence of an entity type
12
Entity Type and Entity Instances
13
AN ENTITY… SHOULD BE: SHOULD NOT BE:
An object that we are trying to model An object that will have many similar instances in the database An object that will be composed of multiple attributes SHOULD NOT BE: A single user of the database system An output of the database system (e.g., a report)
14
Inappropriate entities
Figure 2-4 Example of inappropriate entities Output of the system The company has only one treasurer Inappropriate entities Appropriate entities
15
Strong vs. Weak Entities, and Identifying Relationships
Strong entity exists independently of other types of entities has its own unique identifier (獨特的識別屬性) identifier is underlined with a single line Weak entity cannot exist on its own dependent on a strong entity (identifying owner)… does not have a unique identifier (only a partial identifier) entity box and partial identifier have double lines Identifying relationship Links a strong entity to a weak entity example example
16
Figure 2-5 Example of a weak identity and its identifying relationship
Strong entity Weak entity
17
Attributes (屬性) Attribute–property or characteristic of an entity type or a relationship type Classifications of attributes: Required versus Optional Attributes Simple versus Composite Attribute Single-valued versus Multi-valued Attribute Stored versus Derived (推算的) Attributes Identifier Attributes 5
18
Required vs. Optional Attributes
Required – must have a value for every entity (or relationship) instance with which it is associated Optional – may not have a value for every entity (or relationship) instance with which it is associated 5
19
Simple vs. Composite Attributes
An attribute that has several meaningful component parts (attributes) The address is broken into component parts Figure 2-7 A composite attribute 6
20
Multi-valued and Derived Attributes
Multivalued attribute may have more than one value for a given entity (or relationship) instance Derived attribute values can be calculated from related attribute values (not physically stored in the database) Figure 2-8 Entity with multi-valued attribute (Skill) and derived attribute (Years Employed) Derived Calculated from Date Employed and current date Multi-valued an employee can have more than one skill © 2013 Pearson Education Chapter 2 20 12
21
Identifier Attribute (KEY, 識別屬性)
Identifier (Key) an attribute (or a combination of attributes) that uniquely identifies individual instances of an entity type No two instances of the entity type may have the same value for the identifier Simple versus Composite Identifier Candidate Identifier an attribute that could be a key satisfies the requirements for being an identifier 6
22
Criteria for Identifiers
Choose Identifiers that Will not change in value Will not be null Less likely to lose uniqueness in the future Avoid intelligent identifiers, whose structure indicates classifications, locations, and so on. (e.g., the first two digits of an identifier value may indicate the warehouse. Such codes are often changes.) Substitute simple, single-attribute key for long, composite key conflicts 7
23
Figure 2-9 Simple and composite identifier attributes
The identifier is boldfaced and underlined © 2013 Pearson Education Chapter 2 23 14
24
Naming Attributes in ER-Diagram
Attribute name should be a singular noun (單數名詞) or noun phrase (名詞片語) (e.g., Customer ID) Attribute name should be unique No two attributes of the same entity type have a same name. It is desirable that no two attributes across all entity types have a same name. Name may follow a standard format to make an attribute name unique e.g. [Entity type name { [ Qualifier (修飾語)] } ] attribute class Employee Birth Date Similar attributes of different entity types should use the same qualifiers and attribute classes 7
25
Guidelines (指引) for Defining Attributes
State what the attribute is and possibly why it is important Make it clear what is and is not included in the attribute’s value (i.e., domain) Include aliases in documentation State source of values (例ICD-9-CM國際疾病分類編碼) Specify required vs. optional State min and max number of occurrences allowed for a multi-valued attribute Indicate relationships with other attributes 7
26
domain AND Meaning of Attributes (An Example : Staff and Branch Entity Types)
27
Modeling Relationships in ERD
Relationship Types vs. Relationship Instances A Relationship type is modeled as a line(s) between entity types A Relationship instance is a link between specific entity instances Relationships can have attributes These attributes describe features pertaining to the association between the related entities in a relationship Two entities can have more than one type of relationship (multiple relationships) between them Associative Entity (關聯組合的實體) The presence of one or more attributes on a relationship suggests that the relationship should perhaps be represented as an entity type example
28
Figure 2-10 Relationship types and instances
a) Relationship type : Completes b) Relationship instances © 2013 Pearson Education Chapter 2 28 17
29
Degree (度數) of Relationships
Degree of a relationship The number of entity types that participate in the relationship Unary Relationship Binary Relationship Ternary Relationship 16
30
Degree of relationships – from Figure 2-2
One entity related to another entity of the same entity type Entities of two different types related to each other Entities of three different types related to each other example example example © 2013 Pearson Education Chapter 2 30 8
31
Figure 2-12 Examples of relationships of different degrees
a) Unary relationships © 2013 Pearson Education Chapter 2 31 22
32
Figure 2-12 Examples of relationships of different degrees (cont.)
b) Binary relationships © 2013 Pearson Education Chapter 2 32 22
33
Note: a relationship can have attributes of its own
Figure 2-12 Examples of relationships of different degrees (cont.) c) Ternary relationship Note: a relationship can have attributes of its own © 2013 Pearson Education Chapter 2 33 22
34
Cardinality (基數) of Relationships
One-to-One Each entity in the relationship will have exactly one related entity One-to-Many An entity on one side of the relationship can have many related entities, but an entity on the other side will have a maximum of one related entity Many-to-Many Entities on both sides of the relationship can have many related entities on the other side example
35
Cardinality Constraints
The number of instances of one entity that can or must be associated with each instance of another entity Minimum Cardinality If zero, then optional If one or more, then mandatory Maximum Cardinality The maximum number 29
36
Figure 2-17 Examples of cardinality constraints
a) Mandatory cardinalities 4X4 combinations of binary relationship types maximum cardinality relationship instances A patient history is recorded for one and only one patient A patient must have recorded at least one history, and can have many minimum cardinality © 2013 Pearson Education Chapter 2 36 1
37
Figure 2-17 Examples of cardinality constraints (cont.)
b) One optional, one mandatory relationship instances A project must be assigned to at least one employee, and may be assigned to many An employee can be assigned to any number of projects, or may not be assigned to any at all © 2013 Pearson Education Chapter 2 37 1
38
Figure 2-17 Examples of cardinality constraints (cont.)
c) Optional cardinalities relationship instances A person is married to at most one other person, or may not be married at all © 2013 Pearson Education Chapter 2 38 1
39
The example between Employees and Departments
Figure 2-21 Modeling multiple relationships between entity types The example between Employees and Departments Entities can be related to one another in more than one way Entity EMPLOYEE has 1 unary and 2 binary relationships © 2013 Pearson Education Chapter 2 39 40
40
Figure 2-21 Examples of multiple relationships (cont.)
b) Professors and courses (fixed lower limit constraint) Here, min cardinality constraint is 2. At least two professors must be qualified to teach each course. Each professor must be qualified to teach at least one course. © 2013 Pearson Education Chapter 2 40 40
41
Figure 2-15a and 2-15b Multivalued attributes can be represented as relationships
Simple, multivalued attributes is represented as relationships Composite, multivalued attributes is represented as relationships © 2013 Pearson Education Chapter 2 41
42
Associative Entities (關聯組合的實體)
In ER Diagram, An entity has attributes A relationship links entities together The presence of one or more attributes on a relationship suggests that the relationship should perhaps be represented as an associative entity. When should a relationship with attributes be represented as an associative entity? The relationship is a many-to-many relationship. The associative entity may participate in other relationships other than the relationship that it represents Ternary relationships should be converted to associative entities Example 1 Example 2 example
43
Corresponding associative entity
Figure 2-11a A M:M binary relationship with an attribute Corresponding associative entity Here, the Date Completed attribute pertains specifically to the employee’s completion of a course…it is an attribute of the relationship. © 2013 Pearson Education Chapter 2 43 20
44
Figure 2-11b An associative entity (CERTIFICATE)
Associative entity is like a relationship with attributes, but it is also considered to be an entity in its own right. Note that the many-to-many cardinality between entities in Figure 2-11a has been replaced by 2 one-to-many relationships with the associative entity. © 2013 Pearson Education Chapter 2 44 21
45
Figure 2-13b Two ITEM bill-of-materials structure instances
(車輪罩) (轉鏈輪裝置) Corresponding ERD © 2013 Pearson Education Chapter 2 45 27
46
Figure 2-13c An associative entity – bill of materials structure
This could also be represented as a relationship with attributes…(it’s a judgment call). © 2013 Pearson Education Chapter 2 46 46 27
47
Figure 2-18 Cardinality constraints in a ternary relationship
© 2013 Pearson Education Chapter 2 47 36
48
multivalued attributes
Figure Simple example of time-stamping Composite, multivalued attributes Time stamp – a time value that is associated with a data value, often indicating when some event occurred that affected the data value The Price History attribute is both multi-valued and composite. © 2013 Pearson Education Chapter 2 48 37
49
Figure 2-20c E-R diagram with associative entity for product assignment to product line over time
notation Assignment associative entity shows the date range of a product’s assignment to a particular product line. Modeling time-dependent data has become more important due to regulations such as HIPAA (健康保險可攜與責任法) and Sarbanes-Oxley Act (公司和證券監管法規). © 2013 Pearson Education Chapter 2 49 37
50
Figure 2-22 Data model for Pine Valley Furniture Company in Microsoft Visio notation core entities Different modeling software tools may have different notation for the same constructs. © 2013 Pearson Education Chapter 2 50
51
作業 下一週第一堂上課時交 作業#1 第二章 135~142頁 Problems and Exercises 學號單號:
1 : a, c, e, g, k 2 i & 2 ii : a, b, c 10 (徒手畫或用Word畫) 學號雙號: 1 : b, d, f, h, k 2 i & 2 ii : e, f, g
52
Copyright © 2013 Pearson Education
Summary Copyright © 2013 Pearson Education 52
Similar presentations
© 2025 SlidePlayer.com Inc.
All rights reserved.