Presentation is loading. Please wait.

Presentation is loading. Please wait.

Data Modeling Using the Entity-Relationship

Similar presentations


Presentation on theme: "Data Modeling Using the Entity-Relationship"— Presentation transcript:

1 Data Modeling Using the Entity-Relationship
Chapter 3 Data Modeling Using the Entity-Relationship (ER) Model 3.1 Using High-Level Conceptual Data Models for Database Design 3.2 An Example Database Application 3.3 Entity types, Entity Sets, Attributes, and Keys 3.4 Relationships, Relationship Types, Roles, and Structural Constraints 3.5 Weak Entity Types 3.6 Refining the ER Design for the COMPANY Database 3.7 ER Diagrams, Naming conventions, and Design Issues 3.8 Summary 3-1

2 Figure 3.1 Phases of Database Design (Simplified)
User-defined operations (transactions) Data flow diagrams Data types Relationships constraints 3-2

3 3.2 An Example Database Application: COMPANY
Requirements for the COMPANY Database: The company is organized into DEPARTMENTs. Each department has a unique name, a unique 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. Each department controls a number of PROJECTs. Each project has a unique name, a unique number and is located at a single location. We store each EMPLOYEE’s name, 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. Each employee may have a number of DEPENDENTs. For each dependent, we keep their name, sex, birth date, and relationship to the employee. 3-3

4 Figure 3.2 ER schema diagram for COMPANY database
3-4

5 3.3 Entity types, Entity Sets, Attributes, and Keys
entity data relationship attribute ER Model Concepts 3.3.1 Entities and Attributes Entities are specific objects or things in the mini-world that are represented in the database; for example, the EMPLOYEE John Smith, the Research DEPARTMENT, the ProductX PROJECT. Attributes are properties used to describe an entity; for example, an EMPLOYEE entity may have a Name, SSN, Address, Sex, BirthDate. A specific entity will have a value for each of its attributes; for example a specific employee entity may have Name=‘John Smith’, SSN=‘ ’, Address=‘731 Fondren, Houston, TX’, Sex=‘M’, BirthDate=’09-JAN-55’. Independent existence 3-5

6 Figure 3.3 Two entities and their attribute values
employee department 3-6

7 • Single-valued: single value for that entity (e.g., age)
Types of Attributes: • Simple (Atomic): Each entity has a single atomic value for the attribute; for example SSN or Sex. (不可分) • Composite: The attribute may be composed of several components; for example Address(Apt#, House#, Street, City, State, ZipCode, County) or Name (FirstName, MiddleName, LastName) Composition may form a hierarchy where some components are themselves composite. (see 3-9) (1) • Single-valued: single value for that entity (e.g., age) • Multi-valued: 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} (may have lower and upper bounds) (2) 3-6a

8 -In general, composite and multi-valued attributes may be nested arbitrarily to any number of levels although this is rare. For example, PreviousDegrees of a STUDENT is a composite multi-valued attribute denoted by {PreviousDegrees (College, Year, Degree, Field)}. multi-valued composite • stored • derived Age (derived attribute) is derivable from BirthDate (stored attribute), I.e., Current Date-BirthDate (3) 3-6a

9  not applicable, e.g., Apartment Number, College Degree
(4) Null Values  not applicable, e.g., Apartment Number, College Degree  unknown - the attribute value exists but is missing e.g., Height - it is not known whether the value exists e.g., HomePhone

10 Figure 3.4 A hierarchy of composite attributes
Houston Texas 77001 2311 Kirby Null User sometimes refers to composite attribute, but at other times refers to its components. 3-6b

11 3.3.2 Entity Types, Entity Sets, Keys, and Value Sets
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 (see 3-12) entity type (intension) entity set (extension) 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 key (uniqueness) constraint A key attribute may be composite. For example, VehicleRegistrationNumber is a key of the CAR entity type with components (Number, State). An entity type may have more than one key. For example, the CAR entity type may have two keys: VehicleIdentificationNumber and VehicleRegistraionNumber(Number, State) (see 3-13) 3-6c

12 Figure 3.6 Two entity types and some of the member entities of each
3-8

13 key attribute Figure 3.7 CAR entity type
Component of composite attribute multivalued attribute Registration attribute VehicleID attribute key attribute Uniqueness property must hold for every extension of the entity set 3-9

14 Minit Lname Fname Number Name Name Sex SSN Address Salary Bdate
Locations Sex NumberOf Employee SSN Address Department Salary Bdate EMPLOYEE singled multiple-valued Entity type key attribute derived attribute 3-7

15 Value Sets (Domains) of Attributes
Each simple attribute of an entity type is associated with a value set (or domain of values). e.g. Age:16-70, Name: char string, …  An attribute A of entity type E whose value set is V: e.g. V={1,2} A: E  P(V) power set P(V)={,{1},{2},{1,2}}   null empty set   singled-valued attribute singleton   multivalued attribute no restriction For a composite attribute A, the value set V is Value sets are not displayed in ER diagram. 3-10

16 ( ): composite attribute { }: multivalued attribute
Figure A complex attribute AddressPhone with multivalued and composite component. {AddressPhone({Phone(AreaCode, PhoneNumber)}, Address(StreetAddress(Number, Street, ApartmentNumber), City, State, Zip))} ( ): composite attribute { }: multivalued attribute An employee may have more than one AddressPhone, i.e., office and home. 3-11

17 3.3.3 Initial Conceptual Design of the COMPANY Database
Specification (refer to 3-3) Refer to Fig. 3.2 (3-4) key attribute key attribute Figure { …. } : multivalued attribute ( ) : component of a composite attribute 3-12

18 3.4.1 Relationship Types, Sets and Instances
3.4 Relationships, Relationship Types, Roles, and Structural Constrains DEPARTMENT 3.4.1 Relationship Types, Sets and Instances - A relationship relates two or more distinct entities with a specific meaning; for example, EMPLOYEE John Smith work on the ProductX PROJECT or EMPLOYEE Franklin Wong work for the Research DEPARTMENT. (see 3-19) - 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. MANAGES EMPLOYEE WORKS_ON relationship type PROJECT relationship instance 3-13

19 Figure 3.9 Some instances of the WORKS_FOR relationship many-to-one
3-14

20 3.4.2 Relationship Degree, Role Names, and Recursive Relationships
DEPARTMENT -The degree of a relationship type is the number of participation entity types. Both MANAGES and WORKS_ON are binary relationships ternary relationship: degree 3 (see 3-21) -More than one relationship type can exist with the same participation entity types; for example, MANAGES and WORKS_FOR are distinct relationships between EMPLYEE and DEPARTMENT participate. -Relationship as Attributes WORKS_FOR relationship DEPARTMENT OF EMPLOYEE (see 3-17) EMPLOYEES OF DEPARTMENT : multivalued WORKS_FOR MANAGES EMPLOYEE 3-13

21 Figure 3.10 The ternary relationship SUPPLY s supplies part p to project j
3-15

22 -Role Names and Recursive Relationships.
- A relationship can relate two entities of the same entity type; for example, a SUTERVISION 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. (see 3-23) For example: in the WORKS_FOR relationship type EMPLOYEE WORKS_FOR DEPARTMENT role: employee / worker department / employer 3-13

23 3-17

24 3.4.3 Constrains on Relationship Types
- Cardinality ratio ( of a binary relationship): :1, 1:N, N:1, or M:N MANAGES (1:1, see 3-25) WORKS_FOR (1:N, see 3-19) WORKS_ON ( M:N, see 3-26) Participation constraint(on each participation entity type): total (called existence dependency) or partial Every employee must work for a department. EMPLOYEE in WORKS_FOR : total total participation (完全參與) : double line partial participation (部分參與) : single line structural constraints 3-16

25 Figure 3.12 MANAGES one-to-one 1:1 relationship
Partial participation of EMPLOYEE Total participation of DEPARTMENT 3-18

26 Figure 3.13 WORK_ON M:N relationship
3-19

27 3.3.4 Attributes of Relationship Types
- 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. EMPLOYEE WORKS_ON PROJECT HOUR 3-20

28 - Attributes of 1:1 or 1:N relationship types can be migrated to one of the participating entity types. StartDate 1 1 MANAGES EMPLOYEE DEPARTMENT - For M:N relationship types, some attributes may be determined by the combination of participating entities must be specified as relationship attributes. HOURS N M WORKS_ON EMPLOYEE PROJECT 3-20

29 - For a 1:1 relationship type, a relationship attribute can be migrated to either participating entity types. - For a 1:N relationship type, a relationship attribute can be migrated only to the entity type at the N side. StartDate 1 N WORKS_FOR EMPLOYEE DEPARTMENT 3-20

30 3.5 Weak Entity Types (vs. Strong 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. - Entities are identified by the combination of :  A partial key of the weak entity type set of attributes can uniquely identify weak entities that are related to the same owner entity  The particular entity they are related to in the identifying entity type 3-21

31 A weak entity type always has a total participation constraint
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. A weak entity type always has a total participation constraint with respect to its identifying relationship. (existence dependency) 3-21

32 3.6 Refine the ER Design for COMPANY Database
3-22 1.MANAGES, a 1:1 relationship type between EMPLOYEE and DEPARTMENT. EMPLOYEE participation is partial. DEPARTMENT participation is not clear from the requirements. We question the users, who say that a department must have a manager at all times,which implies total participation.The attribute StartDate is assigned to this relationship type. 2.WORKS_FOR, a 1:N relationship type between DEPARTMENT and EMPLOYEE. Both participations are total. 3.CONTROLS, a 1:N relationship type between DEPARTMENT and PROJECT. The participation of PROJECT is total,whereas that of DEPARTMENT is determined to be partial, after consultation with the users. 3-22

33 4.SUPERVISION, a 1:N relationship type between EMPLOYEE ( in the supervisor role) and EMPLOYEE (in the supervisee role). Both participations are determined to be partial, after the users indicate that not every employee is a supervisor and not every employee has a supervisor. 5.WORKS_ON,determined to be an M:N relationship type with attribute Hours, after the users indicate that a project can have several employees working on it. Both participations are determined to be total. 6.DEPENDENTS_OF, a 1:N relationship type between EMPLOYEE and DEPENDENT, which is also the identifying relationship for the weak entity type DEPENDENT,which is also the identifying relationship for the weak entity type DEPENDENT. The participation of EMPLOYEE is partial, whereas that of DEPENDENT is total. 3-22

34 Figure 3.14 Summary of ER diagram notation
for each entity e in E, e must participate in at least min and at most max relationship instances in R at all times. 3-23

35 - Must have - Derived from the mini-world constraints.
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 - Derived from the mini-world constraints. Examples: (a) A department has exactly one manager and an employee can manage at most one department. - Specify (0,1) for participation of EMPLOYEE in MANAGES - Specify (1,1) for participation of DEPARTMENT in MANAGES (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 min=0 partial participation min>0 total participation 3-23a

36 Figure 3.14 ER diagram for the COMPANY Scheme
Proper Naming of Schema Constructs 3-23b

37 3.7.2 Proper Naming of Schema Constructs
entity types attributes relationship types roles nouns names for verbs Design Choices for ER Conceptual Design A concept may be first modeled as an attribute and then refined into a relationship. An attribute that exists in several entity types may be refined into its own independent entity type. 3-24


Download ppt "Data Modeling Using the Entity-Relationship"

Similar presentations


Ads by Google