Presentation is loading. Please wait.

Presentation is loading. Please wait.

Entity-Relationship (ER) Data Model 概念資料模式 (Based on Chapter 3 in Fundamentals of Database Systems by Elmasri and Navathe, Ed. 4)

Similar presentations


Presentation on theme: "Entity-Relationship (ER) Data Model 概念資料模式 (Based on Chapter 3 in Fundamentals of Database Systems by Elmasri and Navathe, Ed. 4)"— Presentation transcript:

1 Entity-Relationship (ER) Data Model 概念資料模式 (Based on Chapter 3 in Fundamentals of Database Systems by Elmasri and Navathe, Ed. 4)

2 Introduction to Database Systems2 Outline 1Using High-Level Conceptual Data Models for Database Design 2An Example Database Application (COMPANY) 3ER Model Concepts 3.1Entities and Attributes 3.2Entity Types, Value Sets, and Key Attributes 3.3Relationships and Relationship Types 3.4Structural Constraints and Roles 3.4Weak Entity Types 4ER Diagrams Notation 5Relationships of Higher Degree

3 Introduction to Database Systems3 2 COMPANY Database Requirements for the COMPANY Database:( 需 求的文字敘述 ) The company is organized into DEPARTMENTs. Each department has a name, number, and an employee who manages the department. We keep track( 記錄 ) of the start date of the department manager. A department may have several locations.

4 Introduction to Database Systems4 Each department controls a number of PROJECTs. Each project has a name, number, and is located at a single location.

5 Introduction to Database Systems5 We store each EMPLOYEE's social security number, address, salary, sex, and birth date. Each employee works for one department but may work on several projects. We keep track of the number of hours per week that an employee currently works on each project. We also keep track of the direct supervisor of each employee.

6 Introduction to Database Systems6 Each employee may have a number of DEPENDENTs. For each dependent, we keep their name, sex, birth date, and relationship to the employee.

7 Introduction to Database Systems7 3 ER Model Concepts ( 將文字 敘述化為圖形表示 ) Entities ( 實體 )and Attributes( 屬性 ) Entity Types, Value Sets, and Key Attributes Relationships( 關係 ) and Relationship Types Structural Constraints( 結構限制 ) and Roles( 角色 ) Weak Entity Types( 弱實體 )

8 Introduction to Database Systems8 Entities An entity is a “thing” in the real world with an independent existence( 獨立存在 ) ( conceptual or physical ). Entities are specific objects or things in the mini-world that are represented in the database; for example the EMPLOYEE John Smith, the DEPARTMENT Research, the PROJECT ProductX.

9 Introduction to Database Systems9 Attributes Attributes( 屬性 ) are properties( 特性 ) used to describe an entity; for example an EMPLOYEE entity may have a Name, SSN, Address, Sex, BirthDate. 屬性的集合可以表示一個實體 實體以黑點表示

10 Introduction to Database Systems10

11 Introduction to Database Systems11 Types of Attributes Simple( 單一 ) versus Composite( 組合 ) Single-value ( 單值 )versus Multi- valued( 多值 ) Stored ( 儲存 )versus Derived( 推導 )

12 Introduction to Database Systems12 Simple Attributes: Each entity has a single atomic value for the attribute; for example SSN or Sex.

13 Introduction to Database Systems13 Composite Attributes: The attribute may be composed of several components; for example Address(Apt#, House#, Street, City, State, ZipCode, Country) or Name(FirstName, MiddleName, LastName).

14 Introduction to Database Systems14 Single-valued Attributes Most attributes have a single value for a particular entity; such attributes are called single-valued. For example, Age is a single-valued attribute of person.

15 Introduction to Database Systems15 Multi-valued Attributes: An entity may have multiple values for that attribute; for example Color of a CAR or PreviousDegrees of a STUDENT. Denoted as {Color} or {PreviousDegrees}.

16 Introduction to Database Systems16 Stored VS. Derived Attributes In some cases two (or more) attribute values are related. Some attribute values can be derived from related entities. For example, The value of Age can be determined from the current date and the value of that person’s BirthDate.

17 Introduction to Database Systems17 Null Values In some case a particular entity may not have an applicable value for an attributes. For such situations, a special value called null is created.

18 Introduction to Database Systems18 Entity Types( 實體型態 ) Entities with the same basic attributes are grouped or typed into an entity type. ( 同一類東西的集合 ) For example, the EMPLOYEE entity type or the PROJECT entity type. ER Model 不對個別實體描述, 只對型態描 述

19 Introduction to Database Systems19 Entity Sets The collection of all entities of a particular entity type in the database at any point in time is called an entities set. entities set 就是 entity type.

20 Introduction to Database Systems20

21 Introduction to Database Systems21 Key Attributes of an Entities Type An attribute of an entity type for which each entity must have a unique value is called a key attribute of the entity type. For example, SSN of EMPLOYEE.

22 Introduction to Database Systems22 A key attribute may be composite. For example, VehicleRegistrationNumber is a key of the CAR entity type with components (Number, State).

23 Introduction to Database Systems23 An entity type may have more than one key. For example, the CAR entity type may have two keys: VehicleIdentificationNumber and VehicleRegistrationNumber(Number, State).

24 Introduction to Database Systems24 Value Sets (Domains) of Attributes Each simple attributes of an entity type is associated with a value set (or domain of values), which specifies the set of values that may be assigned to that attribute for each individual entity.

25 Introduction to Database Systems25 Relationships( 關係 ) A relationship relates two or more distinct entities with a specific meaning; For example, EMPLOYEE John Smith works on the ProductX PROJECT or EMPLOYEE Franklin Wong manages the Research DEPARTMENT.

26 Introduction to Database Systems26 Relationship Types Relationships of the same type are grouped or typed into a relationship type. For example, the WORKS_ON relationship type in which EMPLOYEEs and PROJECTs participate, or the MANAGES relationship type in which EMPLOYEEs and DEPARTMENTs participate.

27 Introduction to Database Systems27 Relationship Types A relationship type R among n entity types E 1, E 2,…,E n defines a set of associations – or a relationship set – among entities from these types. ER Model 只描述關係型態 (Relationship type), 不描述個別的關係

28 Introduction to Database Systems28 Degree of a Relationship Type The degree of a relationship type is the number of participating entity types. Both MANAGES and WORKS_ON are binary relationships.

29 Introduction to Database Systems29 Relationship types More than one relationship type can exist with the same participating entity types; for example, MANAGES and WORKS_FOR are distinct relationships between EMPLOYEE and DEPARTMENT participate.

30 Introduction to Database Systems30

31 Introduction to Database Systems31 Relationships of Higher Degree Relationship types of degree 2 are called binary Relationship types of degree 3 are called ternary and of degree n are called n-ary In general, an n-ary relationship is not equivalent to n binary relationships

32 Introduction to Database Systems32

33 Introduction to Database Systems33 Roles Names ( 當實體在關係中 的角色不清楚的時候用 ) Each entity type that participates in a relationship type plays a particular role in the relationship. The role name signifies the role that a participating entity from the entity type plays in each relationship instance, and helps to explain what the relationship means.

34 Introduction to Database Systems34 Roles Name For example, in the WORK_FOR relationship type, EMPLOYEE plays the role of employee or worker and DEPARTMENT plays the role of department or employer.

35 Introduction to Database Systems35 Recursive( 自身 ) Relationships A relationship can relate two entities of the same entity type ; ( 使用角色 ) for example, a SUPERVISION relationship type relates one EMPLOYEE (in the role of supervisee ) to another EMPLOYEE (in the role of supervisor ). This is called a recursive relationship type.

36 Introduction to Database Systems36

37 Introduction to Database Systems37 Structural constraints on relationships: Cardinality ratio (of a binary relationship): 1:1, 1:N, N:1, or M:N. Participation constraint (on each participating entity type): total (called existence dependency ) or partial.

38 Introduction to Database Systems38 Cardinality ratios for Binary Relationships. The cardinality ratio( 對應的個數 ) for a binary relationship specifies the number of relationship instances that an entity can participate in. The possible cardinality ratios for binary relationship types are 1:1, 1:N, N:1, M:N.

39 Introduction to Database Systems39

40 Introduction to Database Systems40

41 Introduction to Database Systems41 Participation Constraints The participation constraint( 參加限 制 ) specifies whether the existence of an entity depends on its being related to another entity via the relationship type. There are two types of participation constraints – total and partial.

42 Introduction to Database Systems42 Relationships as Attributes. A relationship type can have attributes; for example, HoursPerWeek of WORKS_ON; its value for each relationship instance describes the number of hours per week that an EMPLOYEE works on a PROJECT.

43 Introduction to Database Systems43 Weak Entity Types( 弱實體型態 ) An entity type that does not have a key attribute. A weak entity type must participate in an identifying relationship type with an owner or identifying entity type.

44 Introduction to Database Systems44 Weak Entity Types Entities are identified by the combination of : A partial key of the weak entity type The particular entity they are related to in the identifying entity type

45 Introduction to Database Systems45 Example: Suppose that a DEPENDENT entity is identified by the dependent's first name and birthdate, and the specific 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.

46 Introduction to Database Systems46

47 Introduction to Database Systems47

48 Introduction to Database Systems48 Alternative (min, max) notation for relationship structural constraints: Specified on each participation of an entity type E in a relationship type R. Specifies that each entity e in E participates in at least min and at most max relationship instances in R. Default(no constraint): min=0, max=n. Must have min 0, max>1. Derived from the mini-world constraints.

49 Introduction to Database Systems49 Examples (a): A department has exactly one manager and an employee can manage at most one department. Specify (1,1) for participation of DEPARTMENT in MANAGES Specify (0,1) for participation of EMPLOYEE in MANAGES

50 Introduction to Database Systems50 Examples (b): An employee can work for exactly one department but a department 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

51 Introduction to Database Systems51


Download ppt "Entity-Relationship (ER) Data Model 概念資料模式 (Based on Chapter 3 in Fundamentals of Database Systems by Elmasri and Navathe, Ed. 4)"

Similar presentations


Ads by Google