1 / 51

Entity-Relationship (ER) Data Model 概念資料模式

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

tvenegas
Download Presentation

Entity-Relationship (ER) Data Model 概念資料模式

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

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

  3. 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. Introduction to Database Systems

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

  5. 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. Introduction to Database Systems

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

  7. 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(弱實體) Introduction to Database Systems

  8. 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. Introduction to Database Systems

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

  10. Introduction to Database Systems

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

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

  13. 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). Introduction to Database Systems

  14. 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. Introduction to Database Systems

  15. 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}. Introduction to Database Systems

  16. 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. Introduction to Database Systems

  17. 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. Introduction to Database Systems

  18. 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 不對個別實體描述,只對型態描述 Introduction to Database Systems

  19. 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. Introduction to Database Systems

  20. Introduction to Database Systems

  21. 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. Introduction to Database Systems

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

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

  24. 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. Introduction to Database Systems

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

  26. RelationshipTypes • 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. Introduction to Database Systems

  27. RelationshipTypes • A relationship type R among n entity types E1, E2,…,En defines a set of associations – or a relationship set – among entities from these types. • ER Model只描述關係型態(Relationship type),不描述個別的關係 Introduction to Database Systems

  28. 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. Introduction to Database Systems

  29. Relationshiptypes • 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. Introduction to Database Systems

  30. Introduction to Database Systems

  31. 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 Introduction to Database Systems

  32. Introduction to Database Systems

  33. 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. Introduction to Database Systems

  34. 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. Introduction to Database Systems

  35. 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. Introduction to Database Systems

  36. Introduction to Database Systems

  37. 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. Introduction to Database Systems

  38. 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. Introduction to Database Systems

  39. Introduction to Database Systems

  40. Introduction to Database Systems

  41. 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. Introduction to Database Systems

  42. 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. Introduction to Database Systems

  43. 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. Introduction to Database Systems

  44. 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 Introduction to Database Systems

  45. 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. Introduction to Database Systems

  46. Introduction to Database Systems

  47. Introduction to Database Systems

  48. 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<max, min>0, max>1. • Derived from the mini-world constraints. Introduction to Database Systems

  49. 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 Introduction to Database Systems

  50. 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 Introduction to Database Systems

More Related