Chapter 3



NOTES II

Data Modeling Using the Entity-Relationship (ER) Data Model

(Based on Chapter 3 in

Fundamentals of Database Systems by Elmasri and Navathe, Ed. 5)

[pic]

3.1 Database Design Process

3.2 Example Database Application (COMPANY)

3.3 ER Model Concepts

3.3.1Entities and Attributes

3.3.2 Entity Types, Value Sets, and Key Attributes

3.3.3 Relationships and Relationship Types

3.3.4 Structural Constraints and Roles

3.3.4 Weak Entity Types

3.4 ER Diagrams Notation

3.5 Relationships of Higher Degree

Chapter 4 Extended Entity Relationship (EER) Model

[pic]

[pic]

[pic]

3.1 Using High-Level Conceptual Data Models for DB design

- Step 1. requirements collection and analysis

a. data requirements

b. functional requirements (operations/transactions/queries)

- Step 2. a. create conceptual schema/conceptual design

(we will use ER and EER derivations to do this)

b. create application program (transaction) design

- Step 3. implementation of the database using a

commerical DB (we will use Oracle for the most part)

a. schema design

(transformed from Step 2 to commerical product)

b. subschema/external design

(transformed from Step 2 to commerical product)

c. application program (transaction) design

(transformed from Step 2 to commerical product)

- Step 4. physical/internal design

INSERT FIGURE 3.1

3.2 Example 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.

- Each department controls a number of PROJECTs. Each project has a name, number, and is located at a single location.

- 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.

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

INSERT FIGURE 3.2

3.3 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='123456789', Address='731 Fondren, Houston, TX', Sex='M', BirthDate='09-JAN-55'.

Types of Attributes:

- Simple: 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, Country) or Name(FirstName, MiddleName, LastName). Composition may form a hierarchy where some components are themselves composite.

- 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}.

- 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)}. Such combinations are referred to as complex attributes.

3.3.2 Entity Types and Key Attributes

Entities with the same basic attributes are grouped or typed into an entity type (entity name). For example, the EMPLOYEE entity type or the PROJECT entity type. I will normally just refer to "entity" and not "entity type."

An attribute of an entity type for which each entity must have a unique value is called a key attribute (uniqueness constraint) of the entity type. For example SSN of EMPLOYEE.

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 VehicleRegistrationNumber(Number, State).

INSERT FIGURE 3.6

3.4.1&2 Relationships, Relationship Types, etc

- 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.

- Relationships of the same entity types defines an association among these entities. These associations are grouped or typed into a relationship type (name). For example, the WORKS_ON relationship type in which EMPLOYEEs and PROJECTs participate, or the MANAGES relationship type in which EMPLOYEEs and DEPARTMENTs participate. I will normally refer to "relationship" and not "relationship type."

- The degree of a relationship type is the number of participating entity types. Both MANAGES and WORKS_ON are binary relationships.

- 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.

INSERT FIGURE 3.9

INSERT FIGURE 3.13

INSERT FIGURE 3.11

- 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.

- 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.

3.4.3 Structural Constraints and Roles

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.

INSERT FIGURE 3.12

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 min0, max>1.

- Derived from the mini-world constraints.

Examples:

(a) A department has exactly one manager and an employee can manage at most one department.

- Specify (1,1) for participation of EMPLOYEE in MANAGES

- Specify (0,1) for participation of EMPLOYEE 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

4.7 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

INSERT FIGURE 3.10

INSERT FIGURE 4.13

INSERT FIGURE 4.14

3.4 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

- 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

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.

INSERT FIGURE 3.14

INSERT FIGURE 3.15

LIMITATIONS OF THE ER MODEL

- No relationship may be defined between an entity type and a relationship type

- No relationship may be defined between an entity type and a collection of entity types from which any one type may participate (e.g. Entity type1 : POLICY-HOLDER may be an individual, multiple individuals , one organization, or many organizations Entity type2 : POLICY )

- No constraints (exclusion, co-existence etc. ) among relationship types. (NIAM model, UML class diagrams allow them).

4 Extended Entity-Relationship (EER)Model

- Incorporates Set-subset Relationships

- Incorporates Generalization and Specialization Hierarchies

Formal Definitions, Section 4.5 p. 92

Class -- a collection of entities

Subclass

Superclass

IS-A relationship

Specialization

Generalization

Inheritance-- attribute, multiple, selected

Category

- Constraints: subclass, disjointness, completeness

- Subclass Constraint: predicate-defined (condition-defined), attribute-defined, user-defined

- Disjointedness Constraint: disjoint vs. overlapping

- completeness Constraint: total and partial

INSERT FIGURE 4.1

INSERT FIGURE 4.2

INSERT FIGURE 4.11

INSERT FIGURE 4.12

The Enhanced E-R Model

The following is still being edited…….

The purpose of this chapter is to present some important extensions to the E-R model (described in Chapter 3).

Specific student objectives are included in the beginning of the chapter. From an instructor’s point of view, the objectives of this chapter are to:

1. Introduce the concept of supertype/subtype relationships, and prepare the student to recognize when to use these relationships in data modeling.

2. Describe the use of specialization (top-down perspective) and generalization (bottom-up perspective) as complimentary techniques for defining supertype/subtype relationships.

3. Introduce notation for specifying both completeness constraints and disjointness constraints when modeling supertype/subtype relationships.

4. Help students gain sufficient perspective so that they recognize when to use (and when not to use) supertype/subtype relationships in realistic business situations.

5. Introduce notation for modeling typical operational constraints that can be incorporated in your EER diagram.

Classroom Ideas

1. Introduce the concept of supertypes and subtypes with a familiar example, such as VEHICLE (subtypes are CAR, TRUCK, SUV, etc.).

2. Introduce the basic notation for supertype/subtype relationships (Figure 4-3). Use this notation to represent the example you introduced in (1).

3. Discuss the EMPLOYEE example with subtypes (Figure 4-1). Use this figure to introduce the example of attribute inheritance.

4. Contrast generalization and specialization using Figures 4-3, 4-4, 4-5, and 4-6.

5. Introduce the completeness constraint using Figure 4-4 and 4-6. Give other examples with total and partial participation.

7. Discuss the disjointness constraint and related notation.

8. Discuss the notion of structural constraints, and illustrate with examples shown in the Figures.

Review Questions

1. Define each of the following terms:

a. Supertype. A generic entity type that has a relationship with one or more subtypes.

b. Subtype. A subgrouping of the entities in an entity type that is meaningful to the organization.

c. Specialization. The process of defining one or more subtypes of the supertype, and forming supertype/subtype relationships.

d. Business rule. A statement that defines or constrains some aspect of the business. It is intended to assert business structure or influence the behavior of the business.

e. Term. A word or phrase that has specific meaning for the business.

f. Fact. An association between two or more terms.

g. Subtype discriminator. An attribute of the supertype whose values determine the target supertype or subtypes.

h. Constraint base. An organized collection of rules (or constraints), usually stored in a repository.

i. Generalization. The process of defining a generalized entity type from a set of more specialized entity types.

j. Disjoint rule. Specifies that if an entity instance (of the supertype) is a member of one subtype, it cannot simultaneously be a member of two (or more) subtypes.

k. Overlap rule. Specifies that an entity instance can simultaneously be a member of two (or more) subtypes.

2. Contrast the following terms:

a. Supertype; subtype. A supertype is a generalized entity type that has one or more subtypes, while a subtype is a subgrouping of the entities in a supertype.

b. Generalization; specialization. Generalization is the process of defining a generalized entity type from a set of more specialized entity types while specialization is the process of defining one or more subtypes of the supertype.

c. Constrained object; constraining object. A constrained object is an object (such as attribute value or relationship instance) whose value (or existence) is constrained by one or more constraining objects.

d. Disjoint rule; overlap rule. With the disjoint rule an instance of a supertype may be a member of only one subtype at a given time. With the overlap rule an instance of a supertype may simultaneously be a member of two or more subtypes.

e. Structural constraint; operational constraint. A structural constraint is a rule that defines the static structure of an organization, while an operational constraint is a rule that constrains the on-going operation of the business.

f. Total participation/specialization rule; partial participation/specialization rule. With the total rule, each instance of the supertype must be a member of some subtype in the relationship. With the partial rule, an instance of the supertype is allowed not to belong to any subtype.

3. Two conditions that indicate a designer should consider using supertype/subtype relationships:

a. There are attributes that apply to some (but not all) of the instances of an entity type.

b. The instances of a subtype participate in the relationship unique to that subtype.

4. An example of a supertype/subtype relationship:

The supertype PERSON has many possible subtypes: MALE, FEMALE, INFANT, TEENAGER, etc.

5. Attribute inheritance is the property that subtype entities inherit values of all attributes of the supertype. This property is important because it makes it unnecessary to include supertype attributes redundantly with subtypes.

6. Give examples of:

a. Supertype/ subtype relationship where the disjoint rule applies: PERSON has subtypes MALE and FEMALE.

b. Supertype/ subtype relationship where the overlap rule applies: PERSON has subtypes INSTRUCTOR and STUDENT

Exercises

1. Match the following terms and definitions:

h supertype

k business rule

i domain constraint

a subtype

j specialization

d constraint base

f term

l subtype discriminator

c attribute inheritance

b overlap rule

e fact

g derived fact

2. An example listing follows:

|Attribute Name |Data Value |

|SSN |736-94-1802 |

|Name |Essica James |

|Address |25 Lake Dr. Medford OR 95106 |

|Sex |female |

|Date_of_Birth |Oct. 23, 1967 |

|Date_Hired |June 10, 1994 |

|Salary |$30,000 |

|Position |Financial anlayst |

8.

9.

7 Mapping ER and EER Schemas into the Relational Model

Steps Of The Algorithm

(Chapter 7, Elmasri/Navathe ed. 4)

- STEP 1: Map Entity Types Regular entities map directly to tables

- STEP 2: Map Weak Entity Types – draw identifier from parent entity type into weak entity type and map directly to table

- Map Relationship Types (STEPS 3 – 5):

1:1 - Choose one of the relations (with total participation if it exists) and insert into this relation the primary key of the other relationas a FK

1:N – the many side provides a FK to the one side, no new relation

M:N – need to set up a separate relation for the relationship with PK from each relation

- STEP 6: Map multivalued attributes – set up a new relation for each multi-valued attribute. Use the PK and value of multi-valued attribute.

- STEP 7: Map higher order relationships (ternary, 4-way, etc.) – each higher order relationship become separate relations.

- STEP 8a: Mapping of generalization hierarchies and set-subset relationships – use the PK of the super class plus the attributes of the subclass.

- STEP 9: Mapping of Union Types – form a surrogate key.

INSERT FIGURE 3.17

INSERT FIGURE 3.16

-----------------------

“L”

“S”

“C”

Payment

Interest

_Rate

Service

_Change

Interest

_Rate

SAVINGS

LOAN

CHECKING

Account_Type=

d

Balance

Account

_Type

Acct_No

Date_Opened

ACCOUNT

O

BIKER

RUNNER

CAMPER

PERSON

O

BIKER

RUNNER

CAMPER

PERSON

d

BIKER

RUNNER

CAMPER

PERSON

d

BIKER

RUNNER

CAMPER

PERSON

Person_Type:

D?=“Y”

V?=“Y”

E?=“Y”

V?

D?

E?

Person_Type

ITEM

Donates

Skill

Date_Hired

EMPLOYEE

VOLUNTEER

DONOR

O

Telephone

City/State/Zip

Address

Name

SSN

PERSON

ITEM

Donates

Skill

Date_Hired

EMPLOYEE

VOLUNTEER

DONOR

O

Telephone

City/State/Zip

Address

Name

SSN

PERSON

Person_Type:

Employee?=“Y”

Student?=“Y”

Alumnus?=“Y”

Student_Type=

“Undergrad”

“Grad”

Employee_Type=

“Staff”

“Faculty”

Position

Test_Score

Class_

Standing

Rank

GRADUATE

STUDENT

UNDERGRAD

STUDENT

STAFF

FACULTY

d

d

Date

Degree

Year

Degrees

Student_Type

Major_Dept

Date_Hired

Employee

_Type

Salary

EMPLOYEE

STUDENT

ALUMNUS

O

Student?

Alumnus?

Employee?

Person_Type

Date_of_

Birth

Sex

SSN

Address

Name

PERSON

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download