Presentation is loading. Please wait.

Presentation is loading. Please wait.

CHAPTER 2: MODELING DATA IN THE ORGANIZATION (THE BASIC ER-MODEL) © 2013 Pearson Education 1 Modern Database Management 11 th Edition, International Edition.

Similar presentations


Presentation on theme: "CHAPTER 2: MODELING DATA IN THE ORGANIZATION (THE BASIC ER-MODEL) © 2013 Pearson Education 1 Modern Database Management 11 th Edition, International Edition."— Presentation transcript:

1 CHAPTER 2: MODELING DATA IN THE ORGANIZATION (THE BASIC ER-MODEL) © 2013 Pearson Education 1 Modern Database Management 11 th Edition, International Edition Jeffrey A. Hoffer, V. Ramesh, Heikki Topi

2 Chapter 2 © 2013 Pearson Education 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 2

3 Chapter 2 © 2013 Pearson Education Objectives  Understand the definitions of terms  Understand the 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 3

4 Chapter 2 © 2013 Pearson Education 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 4

5 Chapter 2 © 2013 Pearson Education 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 : a word or phrase with specific meaning  Fact : an association between two or more terms (A fact is used to relate terms)  Guidelines for good data definition  A concise description of the essential data meaning  Gathered in conjunction with systems requirements  Accompanied by diagrams  Achieved with a team agreement, and iteratively refined 5

6 Chapter 2 © 2013 Pearson Education 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) (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 (a 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) 6 StdSSNStdLastNameStdMajorStdClass 123-45-6789WELLSISFR 124-56-7890NORBERTFINJR 234-56-7890KENDALLACCTJR Student Table E-R diagram example

7 7 Sample E-R Diagram (Figure 2-1) 7 Chapter 2 © 2013 Pearson Education Each ITEM must be supplied by at least one SUPPLIERs. A SUPPLIER may supply many ITEMs.

8 8 Relationship degrees ( 度數 ) specify the number of entity types involved Entity symbols A special entity that is also a relationship Relationship symbols Relationship cardinalities ( 基數 ) specify how many entity instances of each entity type is involved Attribute symbols Basic E-R notation (Figure 2-2) 8 Chapter 2 © 2013 Pearson Education

9 Chapter 2 © 2013 Pearson Education 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. Each ITEM must be supplied by at least one SUPPLIERs. 9 examples

10 Chapter 2 © 2013 Pearson Education A Good Business Rule Is:  Declarative ( 敘述性的 ) : what, not how  Precise : clear, agreed-upon meaning  Atomic : One statement, not several, for each rule. One statement, not several, for each rule.  Consistent : internally and externally  Expressible : structured, natural language  Distinct ( 有區別的 ) : non-redundant  Business-oriented : Understood by business people Understood by business people 10

11 Chapter 2 © 2013 Pearson Education Entities  Entity type A collection of entities that share common properties or characteristics  Entity instance  A single occurrence of an entity type  A person, a place, an object, an event, or a concept in the user environment about which the organization wishes to maintain data 11

12 Chapter 2 © 2013 Pearson Education Entity Type and Entity Instances 12 Instance 1 Instance 2

13 Chapter 2 © 2013 Pearson Education An Entity (Instances) …  SHOULD 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) 13

14 Chapter 2 © 2013 Pearson Education 14 Inappropriate entities The company has only one treasurer Output of the system Figure 2-4 Example of inappropriate entities Appropriate entities

15 Chapter 2 © 2013 Pearson Education 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 15 example

16 Chapter 2 © 2013 Pearson Education 16 Strong entity Weak entity Figure 2-5 Example of a weak identity and its identifying relationship

17 Chapter 2 © 2013 Pearson Education Attributes Attributes ( 屬性 )  Attribute–a 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 17

18 Chapter 2 © 2013 Pearson Education Required vs. Optional Attributes 18 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

19 Chapter 2 © 2013 Pearson Education Simple vs. Composite Attributes  Composite attribute An attribute that has several meaningful component parts (attributes) 19 The address is broken into component parts Figure 2-7 A composite attribute

20 Chapter 2 © 2013 Pearson Education Figure 2-8 Entity with multi-valued attribute (Skill) and derived attribute (Years Employed) Multi-valued an employee can have more than one skill Derived Calculated from Date Employed and current date 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) 20 Chapter 2 © 2013 Pearson Education

21 Chapter 2 © 2013 Pearson Education Identifier Attribute (Key, 識別屬性 )  Identifier (Key 鍵、索引 )  an attribute (or a combination of attributes) that uniquely identifies all the 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 21

22 Chapter 2 © 2013 Pearson Education 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 22 conflicts

23 23 Figure 2-9 Simple and composite identifier attributes The identifier is boldfaced and underlined 23 Chapter 2 © 2013 Pearson Education

24 Chapter 2 © 2013 Pearson Education 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  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 24

25 Chapter 2 © 2013 Pearson Education Guidelines () for Defining Attributes 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 ( 例 )  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 25

26 Chapter 2 © 2013 Pearson Education DOMAIN AND MEANING OF ATTRIBUTES (An Example : Staff and Branch Entity Types)

27 Chapter 2 © 2013 Pearson Education 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 relationship (an association between the related entities)  Two entities can have more than one type of relationship (multiple relationships) between them  Associative Entity  Associative Entity ( 關聯組合的實體 ) The presence of one or more attributes on a relationship suggests that the relationship should perhaps be represented as an entity type 27 example

28 28 Figure 2-10 Relationship types and instances a) Relationship type : Completes b) Relationship instances 28 Chapter 2 © 2013 Pearson Education

29 Chapter 2 © 2013 Pearson Education Degree () of Relationships Degree ( 度數 ) of Relationships  Degree of a relationship The number of entity types that participate in the relationship  Unary Relationship  Binary Relationship  Ternary Relationship 29

30 30 Degree of relationships – from Figure 2-2 Entities of two different types related to each other Entities of three different types related to each other One entity related to another entity of the same entity type 30 Chapter 2 © 2013 Pearson Education example

31 31 Figure 2-12 Examples of relationships of different degrees a) Unary relationships 31 Chapter 2 © 2013 Pearson Education

32 32 Figure 2-12 Examples of relationships of different degrees (cont.) b) Binary relationships 32 Chapter 2 © 2013 Pearson Education

33 33 Figure 2-12 Examples of relationships of different degrees (cont.) c) Ternary relationship Note: a relationship can have attributes of its own 33 Chapter 2 © 2013 Pearson Education

34 Chapter 2 © 2013 Pearson Education 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 34 example

35 Chapter 2 © 2013 Pearson Education Cardinality Constraints  Cardinality Constraints The number of instances of one entity that can or must be associated with each instance of another related entity  Minimum Cardinality  If zero, then optional  If one or more, then mandatory  Maximum Cardinality  The maximum number 35

36 36 Figure 2-17 Examples of cardinality constraints a) Mandatory cardinalities A patient must have recorded at least one visit history, and can have many A patient visit history is recorded for one and only one patient 36 Chapter 2 © 2013 Pearson Education 4X4 combinations of binary relationship types minimum cardinality maximum cardinality relationship instances

37 37 Figure 2-17 Examples of cardinality constraints (cont.) b) One optional, one mandatory An employee can be assigned to any number of projects, or may not be assigned to any at all A project must be assigned to at least one employee, and may be assigned to many 37 Chapter 2 © 2013 Pearson Education relationship instances

38 38 Figure 2-17 Examples of cardinality constraints (cont.) c) Optional cardinalities A person is married to at most one other person, or may not be married at all 38 Chapter 2 © 2013 Pearson Education relationship instances

39 39 Figure 2-21 Modeling multiple relationships between entity types a)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 39 Chapter 2 © 2013 Pearson Education

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. 40 Chapter 2 © 2013 Pearson Education

41 41 Figure 2-15a and 2-15b Multivalued attributes can be represented as relationships 41 Chapter 2 © 2013 Pearson Education Simple, multivalued attributes Composite, multivalued attributes is represented as relationships

42 Chapter 2 © 2013 Pearson Education Associative Entities () 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 42 Example 1 example Example 2

43 43 Figure 2-11a A M:M binary relationship with an attribute Here, the Date Completed attribute pertains specifically to the employee’s completion of a course…it is an attribute of the relationship. 43 Chapter 2 © 2013 Pearson Education Corresponding associative entity

44 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. 44 Chapter 2 © 2013 Pearson Education

45 45 Figure 2-13b Two ITEM bill-of-materials structure instances 45 Chapter 2 © 2013 Pearson Education ( 轉鏈輪裝置 ) ( 車輪罩 ) Corresponding ERD

46 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). 46 Chapter 2 © 2013 Pearson Education

47 47 Figure 2-18 Cardinality constraints in a ternary relationship 47 Chapter 2 © 2013 Pearson Education

48 48 Figure 2-19 Simple example of time-stamping The Price History attribute is both multi-valued and composite. Time stamp – a time value that is associated with a data value, often indicating when some event occurred that affected the data value 48 Chapter 2 © 2013 Pearson Education Composite, multivalued attributes

49 49 Figure 2-20c E-R diagram with associative entity for product assignment to product line over time 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 ( 公司和證券監管法規 ). 49 Chapter 2 © 2013 Pearson Education notation

50 50 Figure 2-22 Data model for Pine Valley Furniture Company in Microsoft Visio notation Different modeling software tools may have different notation for the same constructs. 50 Chapter 2 © 2013 Pearson Education core entities

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 10 ( 徒手畫或用 Word 畫 ) 作業

52 52 Copyright © 2013 Pearson Education Summary


Download ppt "CHAPTER 2: MODELING DATA IN THE ORGANIZATION (THE BASIC ER-MODEL) © 2013 Pearson Education 1 Modern Database Management 11 th Edition, International Edition."

Similar presentations


Ads by Google