Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 4 Entity Relationship (E-R) Modeling Database Systems: Design, Implementation, and Management Peter Rob & Carlos Coronel.

Similar presentations


Presentation on theme: "Chapter 4 Entity Relationship (E-R) Modeling Database Systems: Design, Implementation, and Management Peter Rob & Carlos Coronel."— Presentation transcript:

1 Chapter 4 Entity Relationship (E-R) Modeling Database Systems: Design, Implementation, and Management Peter Rob & Carlos Coronel

2 In this chapter, you will learn: 4How relationships between entities are defined and refined, and how such relationships are incorporated into the database design process 4How ERD components affect database design and implementation 4How to interpret the modeling symbols for the four most popular ER modeling tools 4That real-world database design often requires that you reconcile conflicting goals

3 The Entity Relationship (E-R) Model 4ER model forms the basis of an ER diagram 4ERD represents the conceptual database as viewed by end user 4Main Components u Entities l In E-R models an entity refers to the entity set. l An entity is represented by a rectangle containing the entity’s name. u Attributes l Attributes are represented by ovals and are connected to the entity with a line. l Each oval contains the name of the attribute it represents. l Attributes have a domain -- the attribute’s set of possible values. l Attributes may share a domain. u Relationships

4 The Attributes of the STUDENT Entity

5 Primary Keys 4Underlined in the ER diagram 4Key attributes are also underlined in frequently used table structure shorthand 4Ideally composed of only a single attribute 4Possible to use a composite key: u Primary key composed of more than one attribute

6 The CLASS Table (Entity) Components and Contents

7 The Entity Relationship (E-R) Model 4Classes of Attributes u A simple attribute cannot be subdivided. l Examples: Age, Sex, and Marital status u A composite attribute can be further subdivided to yield additional attributes. l Examples: –ADDRESS  Street, City, State, Zip –PHONE NUMBER  Area code, Exchange number

8 The Entity Relationship (E-R) Model 4Classes of Attributes u A single-valued attribute can have only a single value. l Examples: –A person can have only one social security number. –A manufactured part can have only one serial number. u Multivalued attributes can have many values. l Examples: –A person may have several college degrees. –A household may have several phones with different numbers l Multivalued attributes are shown by a double line connecting to the entity.

9 Multivalued attributes in an Entity

10 The Entity Relationship (E-R) Model 4Multivalued Attribute in Relational DBMS u The relational DBMS cannot implement multivalued attributes. u Possible courses of action for the designer l Within the original entity, create several new attributes, one for each of the original multivalued attribute’s components ( Figure 4.4). l Create a new entity composed of the original multivalued attribute’s components ( Figure 4.5).

11 Splitting the Multivalued Attribute into New Attributes

12 A New Entity Set Composed of Multivalued Attribute’s Components

13 4A derived attribute u may be calculated (derived) from other attributes u Need not be physically stored within the database u Can be derived by using an algorithm u Example: AGE can be derived from the data of birth and the current date. The Entity Relationship (E-R) Model

14 Depiction of a Derived Attribute

15 4Relationships u A relationship is an association between entities. u Relationships are represented by diamond-shaped symbols. The Entity Relationship (E-R) Model

16 4Connectivity u The term connectivity is used to describe the relationship classification (e.g., one-to-one, one-to-many, and many-to-many). The Entity Relationship (E-R) Model

17 4Cardinality u Cardinality expresses the specific number of entity occurrences associated with one occurrence of the related entity. u The minimum and maximum number of entity occurrences The Entity Relationship (E-R) Model

18 Connectivity and Cardinality in an ERD

19 4Existence Dependent u If an entity’s existence depends on the existence of one or more other entities, it is said to be existence- dependent. u CLASS is existence-dependent on COURSE (parent entity) u EMPLOYEE claims DEPENDENT— DEPENDENT is existence-dependent on EMPLOYEE 4Existence independent u Entity can exist apart from one or more related entities u Example: l some of parts are produced “in-house” and other parts are bought from vendors. At least some of the parts are not supplied by a vender. l PART is existence-independent from VENDOR Relationship Strength

20 4Weak (non-identifying) relationship u One entity is not existence-independent on another entity u PK of related entity doesn’t contain PK component of parent entity l COURSE( CRS_CODE, …) l CLASS( CLASS_CODE, …) 4Strong (identifying) relationship u One entity is existence-dependent on another u PK of related entity contains PK component of parent entity l COURSE( CRS_CODE, …) l CLASS( CRS_CODE, CLASS_SECTION, …) Relationship Strength

21 A Weak Relationship Between COURSE and CLASS

22 A Strong (Identifying) Relationship Between COURSE and CLASS

23 4Relationship Participation u Optional l The participation is optional if one entity occurrence does not require a corresponding entity occurrence in a particular relationship. l An optional entity is shown by a small circle on the side of the optional entity. u Mandatory l Entity occurrence requires corresponding occurrence in related entity l If no optionality symbol is shown on ERD, it is mandatory The Entity Relationship (E-R) Model

24 CLASS is Optional to COURSE COURSE is Mandatory to CLASS COURSE and CLASS in a Mandatory Relationship

25 4Weak Entities u A weak entity is an entity that l Is existence-dependent and l Has a primary key that is partially or totally derived from the parent entity in the relationship. u The existence of a weak entity is indicated by a double rectangle. u The weak entity inherits all or part of its primary key from its strong counterpart. Relationship Strength and Weak Entities

26 A Weak Entity in an ERD EMPLOYEE( EMP_NUM, EMP_LNAME, EMP_FNAME, EMP_INITIAL, EMP_DOB ) DEPENDENT( EMP_NUM, DEP_NUM, DEP_FNAME, DEP_DOB ) Primary Key DEP_NUM

27 Weak entity in a Strong Relationship Between DEPENDENT and EMPLOYEE ( EMP_NUM + DEP_NUM ) ( EMP_NUM )

28 4Weak relationship u One entity is not existence-independent on another u PK of related entity doesn’t contain PK component of parent entity l COURSE( CRS_CODE, …) l CLASS( CLASS_CODE, …) 4Strong relationship u One entity is existence-dependent on another u PK of related entity contains PK component of parent entity l COURSE( CRS_CODE, …) l CLASS( CRS_CODE, CLASS_SECTION, …) 4In any case, CLASS is always existence-dependent on COURSE, whether or not it is defined to be weak. Weak entity in a Strong Relationship Not Weak entity

29 4A relationship’s degree indicates the number of associated entities or participants. u A unary relationship exists when an association is maintained within a single entity. u A binary relationship exists when two entities are associated. u A ternary relationship exists when three entities are associated. Relationship Degree

30 The Implementation of a Ternary Relationship Researchers

31 4Recursive relationship u A recursive relationship is one in which a relationship can exist between occurrences of the same entity set. u A recursive entity is found within a unary relationship. The Entity Relationship (E-R) Model

32 1:1 Recursive relationship EMPLOYEE is married to EMPLOYEE

33 1:M Recursive relationship PART contains PART each part is used to create only one rotor assembly C130 = 4× AA × AB …

34 M:N Recursive relationship PART Contains PART A part_ can be used to create several different kinds of other parts A part_ is itself composed of many parts. PART contains PART contains COMPONENT

35

36 M:N Recursive relationship COURSE Requires COURSE

37 Implementation of the 1:M “EMPLOYEE Manages EMPLOYEE” Recursive Relationship

38 4Composite Entities u A composite entity is composed of the primary keys of each of the entities to be connected. u The composite entity serves as a bridge between the related entities. u The composite entity may contain additional attributes. The Entity Relationship (E-R) Model

39 4Composite Entities The Entity Relationship (E-R) Model

40 Converting the M:N Relationship Into Two 1:M Relationships

41 At the start of registration A class may exist even though it contains no students at all A student has not yet signed up for any classes.

42 A Composite Entity in the ERD

43 4Entity Supertypes and Subtypes u Describing the different types of employees within a single entity would be awkward at best. u Example : Aviation business ( Figure 4.27) the special pilot characteristics (EMP_LICENCE, EMP_RATING, EMP_MED_TYPE) would cause a large number of nulls for other employees who are not pilots. The Entity Relationship (E-R) Model

44 Nulls Created by Unique Attributes

45 4Generalization hierarchy u Depicts relationships between higher-level supertype and lower-level subtype entities. u Supertype contains the shared attributes u Subtype contains the unique attributes. u A subtype entity inherits its attributes and its relationships from the supertype entity. The Entity Relationship (E-R) Model

46 A Generalization Hierarchy Disjoint relationships are indicated by G

47 4Disjoint Supertypes u Also known as non-overlapping subtypes u Subtypes that contain a subset of the supertype entity set u Each entity instance (row) of the supertype can appear in only one of the disjoint subtypes. u The supertype and its subtype(s) maintain a 1:1 relationship. The Entity Relationship (E-R) Model

48 The EMPLOYEE/PILOT Supertype/Subtype Relationship

49 A Generalization Hierarchy with Overlapping Subtypes Overlapping relationships are indicated by Gs

50 A Comparison of ER Modeling Symbols

51 SUMMARY

52 The Chen Representation of the Invoicing Problem

53 The Crow’s Foot Representation of the Invoicing Problem

54 The Rein85 Representation of the Invoicing Problem

55 The IDEF1X Representation of the Invoicing Problem

56 Developing an E-R Diagram 4The process of database design is an iterative rather than a linear or sequential process. 4Based on repetition of processes and procedures. 4The basic E-R model is graphically depicted and presented for review. 4The process is repeated until the end users and designers agree that the E-R diagram is a fair representation of the organization’s activities and functions.

57 4Tiny College Database (1) u Tiny College (TC) is divided into several schools. Each school is administered by a dean. u A 1:1 relationship exists between DEAN and SCHOOL. u Each dean is a member of a group of administrators (ADMINISTRATOR). u Deans also hold professorial rank and may teach a class ( PROFESSOR). u Administrators and professors are also Employees. Developing an E-R Diagram

58 A Supertype/Subtype Relationship

59 Developing an E-R Diagram 4Tiny College Database (0) u Most DBMS do not support supertype/subtype relationship directly. u At the implementation level, designers convert it into a 1:1 relationship. u A PROFESSOR is an EMPLOYEE. u An EMPLOYEE is not required to be a PROFESSOR. u PROFESSOR is optional to EMPLOYEE. u PROFESSOR is existence-dependent on EMPLOYEE, and it inherits its PK from EMPLOYEE. Therefore the relationship between EMPLOYEE and PROFESSOR is strong, while is PROFESSOR a weak entity.

60 A Supertype/Subtype Relationship in an ERD

61 Developing an E-R Diagram 4Tiny College Database (1) u Each school is composed of several departments. u The smallest number of departments operated by a school is one, u and the largest number of departments is indeterminate (N). u Each department belongs to only a single school.

62 4Tiny College Database (2) u Each department offers several courses. u courses is optional to department. (Some departments are research only.) Developing an E-R Diagram

63 4Tiny College Database (3) u A department may offer several classes of the same course. u A 1:M relationship exists between COURSE and CLASS. u CLASS is optional to COURSE Developing an E-R Diagram

64 4Tiny College Database (4) u Each department has many professors assigned to it. u One of those professors chairs the department. Only one of the professors can chair the department. u DEPARTMENT is optional to PROFESSOR in the “chairs” relationship. Developing an E-R Diagram

65 4Tiny College Database (5) u Each professor may teach up to four classes, each one a section of a course. u A professor may also be on a research contract and teach no classes. Developing an E-R Diagram

66 4Tiny College Database (6) u A student may enroll in several classes, but (s)he takes each class only once during any given enrollment period. u Each student may enroll in up to six classes and each class may have up to 35 students in it. u STUDENT is optional to CLASS. Developing an E-R Diagram

67 4Tiny College Database (8) u Each department has several students whose major is offered by that department. u Each student has only a single major and associated with a single department. u It is possible, at least for a while, for a student not to declare a major filed of study. DEPARTMENT is optional to STUDENT. Developing an E-R Diagram

68 4Tiny College Database (8) u Each student has an advisor in his or her department; each advisor counsels several students. u An advisor is also a professor, but not all professors advise students. Developing an E-R Diagram

69 Components of the ER Model

70 Diagram from 6th edit. Not yet updated.

71 The Completed Tiny College ERD

72 The Challenge of Database Design: Conflicting Goals 4Database design must conform to design standards 4High processing speeds are often a top priority in database design 4Conflicting Goals u Design standards (design elegance) u Processing speed (high-transaction-speed) 4require design compromises u Example: 1:1 supertype/subtype relationship l Two tables (avoid nulls) l a single table (high speed)

73 MAR_DATE

74 The Challenge of Database Design: Conflicting Goals 4A recursive 1:1 relationship yields many different solutions. 4Your job as a database designer is to use your professional judgment to yield a solution that meets the requirements.

75 Summary 4Entity relationship (ER) model u Uses ER diagrams to represent conceptual database as viewed by the end user u Three main components l Entities l Relationships l Attributes u Includes connectivity and cardinality notations 4Connectivities and cardinalities are based on business rules

76 Summary ( continued ) 4ER symbols are used to graphically depict the ER model’s components and relationships 4ERDs may be based on many different ER models 4Entities can also be classified as supertypes and subtypes within a generalization hierarchy 4Database designers are often forced to make design compromises


Download ppt "Chapter 4 Entity Relationship (E-R) Modeling Database Systems: Design, Implementation, and Management Peter Rob & Carlos Coronel."

Similar presentations


Ads by Google