Advanced Data Modelling

Introduction:

  • The extended entity relationship model (EERM)is the result of adding more semantic constructs to the original ER model

    • It is sometimes referred to as the enhanced entity relationship model

  • A diagram that uses the EERM is called EER diagram (EERD)

In the following sections, you will learn about the main EER model constructs—entity supertypes, entity subtypes, and entity clustering—and see how they are represented in ERDs or EERDs.

Entity Supertypes and Subtypes:

Because most employees possess a wide range of skills and special qualifications, data modelers must find a variety of ways to group employees based on their characteristics.

  • The grouping of employees into various types provides the following two benefits:

    • It avoids unnecessary nulls in attributes when some employees have characteristics that are not shared by other employees

    • It enables a particular employee type to participate in relationships that are unique to that employee type

  • An entity supertype is a generic entity type related to one or more entity subtypes

    • The entity supertype contains common characteristics

  • The entity subtype contains unique characteristics of each entity subtype

  • Two criteria help the designer determine when to use subtypes and supertypes:

    • There must be different, identifiable kinds of the entity in the user’s environment

    • The different kinds or types of instances should each have one or more attributes that are unique to that kind or type of instance

Specialisation Hirearchy

  • Entity supertypes and subtypes are organized in a specialization hierarchy, which depicts the arrangement of higher-level entity supertypes and lower-level entity subtypes

    • The relationships are described in terms of “is-a” relationships

  • Within a specialization hierarchy, a subtype can only exist within the context of a supertype

    • Every subtype has only one supertype to which it is directly related

  • A supertype can have many subtypes

  • A specialization hierarchy provides the means to do the following:

    • Support attribute inheritance

    • Define a special supertype attribute known as the subtype discriminator

    • Define disjoint or overlapping constraints and complete or partial constraints

An example of a specialization heirarchy

Inheritance

  • The property of inheritance enables an entity subtype to inherit attributes and relationships of the supertype

    • All entity subtypes inherit their primary key attribute from their supertype

  • At the implementation level, the supertype and its subtype(s) maintain a 1:1 relationship

  • Entity subtypes inherit all relationships in which supertype entity participates

  • Lower-level subtypes inherit all attributes and relationships from its upper-level supertypes

An example of a Specialization Hierarchy with Overlapping Subtypes

Subtype Discriminator:

  • A subtype discriminator is the attribute in the supertype entity that determines to which subtype the supertype occurrence is related

  • The default comparison condition for the subtype discriminator attribute is the equality comparison

  • In some situations the subtype discriminator is not necessarily based on an equality comparison

Disjoint and Overlapping Constraints

  • Disjoint subtypes are subtypes that contain a unique subset of the supertype entity set

    • Also known as nonoverlapping subtypes

    • The implementation of disjoint subtypes is based on the value of the subtype discriminator attribute in the supertype

  • Overlapping subtypes are subtypes that contain nonunique subsets of the supertype entity set

    • Implementation of overlapping subtypes requires the use of one discriminator attribute for each subtype

Discriminator Attributes with Overlapping Subtypes

Discriminator Attributes


Movie

Book

Comment

Y

N

The Story is a member of the  Movie subtype

N

Y

The Story is a member of the  Book subtype

Y

Y

The Story is both a Movie and a Book

N

N

The Story is not required to be a member of any subtype. Only possible if the hierarchy exhibits the partial completeness constraint (see next section).

Completeness Constraint:

  • The completeness constraint specifies whether each supertype occurrence must also be a member of at least one subtype

  • Partial completeness means that not every supertype occurrence is a member of a subtype

   Partial Completeness Symbol

  • Total completeness means that every supertype occurrence must be a member of at least one subtypes

Total Completeness Symbol

Specialization Hierarchy Constraint Scenarios

Type

Disjoint Constraint

Overlapping Constraint

Partial 

Supertype has optional subtypes.
Subtype discriminator can be null.
Subtype sets are unique.

Supertype has optional subtypes.
Subtype discriminators can be null.
Subtype sets are not unique.

Total

Every supertype occurrence is a member of only one subtype.
Subtype discriminator cannot be null.
Subtype sets are unique.

Every supertype occurrence is a member of at least one subtype.
Subtype discriminators cannot be null.
Subtype sets are not unique.

Specialisation and Generalisation:

  • Specialization is the top-down process of identifying lower-level, more specific entity subtypes from a higher-level entity supertype

    • Specialization is based on grouping unique characteristics and relationships of the subtypes

  • Generalization is the bottom-up process of identifying a higher-level, more generic entity supertype from lower-level entity subtypes

    • Generalization is based on grouping common characteristics and relationships of the subtypes

Entity Clustering:

  • An entity cluster is a “virtual” entity type used to represent multiple entities and relationships in the ERD

  • An entity cluster is formed by combining multiple interrelated entities into a single, abstract entity object

  • The general rule is to avoid the display of attributes to eliminate complications that result when the inheritance rules change

The following example illustrates the use of entity clusters based on the Tiny College example in Module 4. Note that the ERD contains two entity clusters:

  • OFFERING, which groups the SEMESTER, COURSE, and CLASS entities and relationships

  • LOCATION, which groups the ROOM and BUILDING entities and relationships

Entity Integrity: Selecting Primary Keys

The most important characteristic of an entity is its primary key (a single attribute or some combination of attributes), which uniquely identifies each entity instance. The primary key’s function is to guarantee entity integrity. 

In addition, primary keys and foreign keys work together to implement relationships in the relational model. Therefore, the importance of properly selecting the primary key has a direct bearing on the efficiency and effectiveness of database implementation.

Natural Keys and Primary Keys

  • A natural key or natural identifier is a real-world identifier used to uniquely identify real-world objects

    • It is familiar to end users and forms part of their day-to-day business vocabulary

  • Usually, if an entity has a natural identifier, a data modeler uses it as the primary key of the entity being modeled 

PK Characteristic

Rationale

Unique values

The PK must uniquely identify each entity instance. A primary key must be able to guarantee unique values. It cannot contain nulls.

Nonintelligent

The PK should not have embedded semantic meaning other than to uniquely identify each entity instance.

No change over time

The PK should be permanent and unchangeable.

Preferably single-attribute

A primary key should have the minimum number of attributes possible (irreducible). Single-attribute primary keys simplify the implementation of foreign keys.

Perferably numeric

Unique values can be better managed when they are numeric because the database can use internal routines to implement a counter-style attribute that automatically increments values with the addition of each new row.

Security-compliant

The selected primary key must not be composed of any attribute(s) that might be considered a security risk or violation.

When to Use Composite Primary Keys

  • Composite primary keys are useful in the following two cases:

    • As identifiers of composite entities, in which each primary key combination is allowed once in M:N relationship

    • As identifiers of weak entities, in which the weak entity has a strong identifying relationship with the parent entity

      • Represents a real-world object that is existence-dependent on another real-world object

      • A real-world object that is represented in the data model as two separate entities in a strong identifying relationship

When to Use Surrogate Primary Keys

  • A surrogate key is a primary key created by the database designer to simplify the identification of entity instances 

  • One advantage of a surrogate key is that because it has no intrinsic meaning, values for it can be generated by the DBMS to ensure that unique values are always provided

  • Surrogate keys  are useful in the following situations:

    • When there is no natural key

    • When the selected candidate key has embedded semantic contents

    • When the selected candidate key is too long 

Design Cases: Learning Flexible Database Design

Data modeling and database design require skills that are acquired through experience. In turn, experience is acquired through practice—regular and frequent repetition, applying the concepts learned to specific and different design problems. 

This section presents four special design cases that highlight the importance of flexible designs, proper identification of primary keys, and placement of foreign keys.

Design Case 1: Implementing 1:1 Relationships

  • Foreign keys work with primary keys to properly implement relationships in the relational model

    • The basic rule is: put the primary key of the parent entity on the dependent entity as a foreign key

  • Options for selecting and placing the foreign key include the following:

    • Place a foreign key in both entities

    • Place a foreign key in one of the entities 

Case

ER Relationship Constraints

Action

I

One side is mandatory and the other side is optional.

Place the PK of the entity on the mandatory side in the entity on the optional side as an FK, and make the FK mandatory.

II

Both sides are optional.

Select the FK that causes the fewest nulls, or place the FK in the entity in which the (relationship) role is played.

III

Both sides are mandatory.

See Case II, or consider revising your model to ensure that the two entities do not belong together in a single entity.

Example:

→  Note in this case, EMPLOYEE is mandatory to DEPARTMENT. Therefore, EMP_NUM is placed as the foreign key in DEPARTMENT. Alternatively, you might also argue that the “manager” role is played by the EMPLOYEE in the DEPARTMENT.


Design Case 2: Maintaining History of Time-Variant Data

  • Time-variant data refers to data whose values change over time and for which a history of the data changes must be retained

  • To model time-variant data, you must create a new entity in a 1:M relationship with the original entity 

  • This new entity contains the new value, the date of the change, and any other pertinent attribute

Examples:

Maintaining Salary History

If you want to track salary histories for each employee, then the EMP_SALARY attribute becomes multivalued, as shown below. In this case, for each employee, there will be one or more records in the SALARY_HIST entity, which stores the salary amount and the date when the new salary goes into effect.

Maintaining Manager History

Other time-variant data can turn a 1:M relationship into an M:N relationship. Assume that in addition to employee data, your data model includes data about the different departments in the organization and which employee manages each department. Assuming that each department is managed by only one employee and each employee can manage one department at most, then a 1:1 relationship would exist between EMPLOYEE and DEPARTMENT. This relationship would record the current manager of each department. However, if you want to keep track of the history of all department managers as well as the current manager, you can create the model shown below.

Maintaining Job History

Now suppose you would like to keep track of the job history for each of the company’s employees—you’d probably want to store the department, the job code, the date assigned, and the salary. To accomplish that task, you could modify the model in the figure for Maintaining Manager History by adding a JOB_HIST entity. The figure below shows the use of the new JOB_HIST entity to maintain the employee’s history.

Design Case 3: Fan Traps

  • A design trap occurs when a relationship is improperly or incompletely identified, and is represented in a way not consistent with the real world

    • The most common design trap is known as a fan trap

  • A fan trap occurs when you have one entity in two 1:M relationships to other entities

    • It produces an association among other entities not expressed in the model

Example: assume that the JCB basketball league has many divisions. Each division has many players, and each division has many teams. Given those “incomplete” business rules, you might create an ERD that looks like the one below.

Although that representation is semantically correct, the relationships are not properly identified. For example, there is no way to identify which players belong to which team.

Now the correct ERD after the fan trap has been eliminated. Note that, in this case, DIVISION is in a 1:M relationship with TEAM. In turn, TEAM is in a 1:M relationship with PLAYER. The figure below also shows the instance relationship representation after eliminating the fan trap.

Note how easy it is to see which players play for which team.

However, to find out which players play in which division, you first need to see what teams belong to each division, and then you need to find out which players play on each team. In other words, there is a transitive relationship between DIVISION and PLAYER via the TEAM entity.

Design Case 4:  Redundant Relationships 

  • Redundant relationships occur when there are multiple relationship paths between related entities

    • The main concern is that they remain consistent across the model

  • Some designs use redundant relationships as a way to simplify the design

Example:

Note the transitive 1:M relationship between DIVISION and PLAYER through the TEAM entity set. Therefore, the relationship that connects DIVISION and PLAYER is redundant, for all practical purposes. 

In that case, the relationship could be safely deleted without losing any information-generation capabilities in the model. 

Remember, you can determine the player’s division through the TEAM entity.