19
COMP102: Introduction to Databases, 13 Dr Muhammad Sulaiman Khan Department of Computer Science University of Liverpool U.K. 7 March, 2011 Dr Muhammad Sulaiman Khan COMP102: Introduction to Databases, 13

COMP102: Introduction to Databases, 13cgi.csc.liv.ac.uk/~khan/comp102/lecture15-2011.pdf · The Enhanced Entity Relationship (EER) ... translating EER diagram into tables ... Dr Muhammad

  • Upload
    vuque

  • View
    219

  • Download
    0

Embed Size (px)

Citation preview

Page 1: COMP102: Introduction to Databases, 13cgi.csc.liv.ac.uk/~khan/comp102/lecture15-2011.pdf · The Enhanced Entity Relationship (EER) ... translating EER diagram into tables ... Dr Muhammad

COMP102: Introduction to Databases, 13

Dr Muhammad Sulaiman Khan

Department of Computer ScienceUniversity of Liverpool

U.K.

7 March, 2011

Dr Muhammad Sulaiman Khan COMP102: Introduction to Databases, 13

Page 2: COMP102: Introduction to Databases, 13cgi.csc.liv.ac.uk/~khan/comp102/lecture15-2011.pdf · The Enhanced Entity Relationship (EER) ... translating EER diagram into tables ... Dr Muhammad

Logical Database Design:

Enhanced ER Modeling

Dr Muhammad Sulaiman Khan COMP102: Introduction to Databases, 13

Page 3: COMP102: Introduction to Databases, 13cgi.csc.liv.ac.uk/~khan/comp102/lecture15-2011.pdf · The Enhanced Entity Relationship (EER) ... translating EER diagram into tables ... Dr Muhammad

Specific topics for today:

The limitations of the basic ER modeling concepts and therequirements to model more complex applications usingenhanced data modeling concepts.

The main concepts of the Enhanced Entity Relationship(EER) model called specialization/generalization.

UML notation for displaying specialization/generalization inan EER diagram.

How to create tables that representspecialization/generalization in an EER model.

Dr Muhammad Sulaiman Khan COMP102: Introduction to Databases, 13

Page 4: COMP102: Introduction to Databases, 13cgi.csc.liv.ac.uk/~khan/comp102/lecture15-2011.pdf · The Enhanced Entity Relationship (EER) ... translating EER diagram into tables ... Dr Muhammad

The Enhanced Entity Relationship (EER) model

Basic concepts are often perfectly adequate for therepresentation of the data requirements for many differentdatabase applications.

However, basic concepts can be limiting when modeling morecomplex database applications with a large amount of data aand/or data with complex interrelationships.

Stimulated need to develop additional semantic modelingconcepts.

Original ER model with additional semantic concepts isreferred to as the Enhanced Entity Relationship (EER) model.

One of the most useful concepts of the EER model is calledspecialization/generalization.

Dr Muhammad Sulaiman Khan COMP102: Introduction to Databases, 13

Page 5: COMP102: Introduction to Databases, 13cgi.csc.liv.ac.uk/~khan/comp102/lecture15-2011.pdf · The Enhanced Entity Relationship (EER) ... translating EER diagram into tables ... Dr Muhammad

Specialization/generalization

Associated with special types of entities known as superclassesand subclasses, and the process of attribute inheritance.

Superclass: An entity that includes one or more distinctgroupings of its occurrences, which require to be representedin a data model.

Subclass: A distinct grouping of occurrences of an entity type,which require to be represented in a data model.

Superclass/subclass relationship:

Superclass/subclass relationship is one-to-one (1:1).Each member of a subclass is also a member of the superclassbut has a distinct role.

Dr Muhammad Sulaiman Khan COMP102: Introduction to Databases, 13

Page 6: COMP102: Introduction to Databases, 13cgi.csc.liv.ac.uk/~khan/comp102/lecture15-2011.pdf · The Enhanced Entity Relationship (EER) ... translating EER diagram into tables ... Dr Muhammad

Superclasses and subclasses

We can use superclasses and subclasses to avoid describingdifferent types of entities with possibly different attributeswithin a single entity.

Can also show relationships that are only associated withparticular subclasses and not with superclass.

Adds more semantic information to the design of a form:“manager IS-A member of Staff”, “van IS-A type of vehicle”.

Dr Muhammad Sulaiman Khan COMP102: Introduction to Databases, 13

Page 7: COMP102: Introduction to Databases, 13cgi.csc.liv.ac.uk/~khan/comp102/lecture15-2011.pdf · The Enhanced Entity Relationship (EER) ... translating EER diagram into tables ... Dr Muhammad

Example: AllStaff table holding details of all staff:

Dr Muhammad Sulaiman Khan COMP102: Introduction to Databases, 13

Page 8: COMP102: Introduction to Databases, 13cgi.csc.liv.ac.uk/~khan/comp102/lecture15-2011.pdf · The Enhanced Entity Relationship (EER) ... translating EER diagram into tables ... Dr Muhammad

Attribute inheritance

An entity occurrence in a subclass represents the same realworld object as in the superclass.Hence, a member of a subclass inherits those attributesassociated with the superclass, but may also havesubclass-specific attributes.Example: SalesPersonnel is subclass of the superclass Staff:

Inherited attributes of subclass SalesPersonnel: staffNo, name,position, salary, branchNo.Subclass-specififc attributes of subclass SalesPersonnel:salesArea, vehLicenseNo, carAllowance.

An entity and its subclasses and their subclacces, and so on, iscalled type hierarchy.Type hierarchy is also known under many different names:

Specialization hierarchy: e.g., Manager is specialization ofStaff.Generalization hierarchy: e.g., Staff is generalization ofManager.IS-A hierarchy: e.g., Manager IS-A (member of) Staff.

Shared subclass: Subclass having more than one superclass.Dr Muhammad Sulaiman Khan COMP102: Introduction to Databases, 13

Page 9: COMP102: Introduction to Databases, 13cgi.csc.liv.ac.uk/~khan/comp102/lecture15-2011.pdf · The Enhanced Entity Relationship (EER) ... translating EER diagram into tables ... Dr Muhammad

Specialization/generalization

Specialization:

The top-down process of maximizing the differences betweenmembers of an entity by identifying their distinguishingcharacteristics.Given superclass(es) it leads to identifying subclass(es).

Generalization:

The bottom-up process of minimizing the differences betweenentities by identifying their common characteristics.Given subclass(es) it leads to identifying superclass(es).

Dr Muhammad Sulaiman Khan COMP102: Introduction to Databases, 13

Page 10: COMP102: Introduction to Databases, 13cgi.csc.liv.ac.uk/~khan/comp102/lecture15-2011.pdf · The Enhanced Entity Relationship (EER) ... translating EER diagram into tables ... Dr Muhammad

Example: Staff entity with subclasses representing job roles (UMLdiagram): Note: multiplicuty of Manager in Manages is 1..1;

multiplicity of Staff in Manages was 0..1.

Dr Muhammad Sulaiman Khan COMP102: Introduction to Databases, 13

Page 11: COMP102: Introduction to Databases, 13cgi.csc.liv.ac.uk/~khan/comp102/lecture15-2011.pdf · The Enhanced Entity Relationship (EER) ... translating EER diagram into tables ... Dr Muhammad

Example: Entity Staff: Shared subclass and a subclass with itsown subclass (UML diagram):

Dr Muhammad Sulaiman Khan COMP102: Introduction to Databases, 13

Page 12: COMP102: Introduction to Databases, 13cgi.csc.liv.ac.uk/~khan/comp102/lecture15-2011.pdf · The Enhanced Entity Relationship (EER) ... translating EER diagram into tables ... Dr Muhammad

Example: from the previous slide, contd.:

Subclass SalesManager is a shared subclass.

Thus: Member of the subclass SalesManager is also amember of classes Manager, SalesPersonnel, and Staff.

Also: Attributes of the superclass Staff, and attributes of thesubclasses Manager and SalesPersonnel are inherited by theSalesManager subclass, which also has its own attribute calledsalesTarget.

Subclass Secretary has its own subclass AssistantSecretary.

Dr Muhammad Sulaiman Khan COMP102: Introduction to Databases, 13

Page 13: COMP102: Introduction to Databases, 13cgi.csc.liv.ac.uk/~khan/comp102/lecture15-2011.pdf · The Enhanced Entity Relationship (EER) ... translating EER diagram into tables ... Dr Muhammad

Constraints on specialization/generalization

Two constraints may apply to a specialization/generalizationcalled participation constraints and disjoint constraints.

Participation constraint:Determines whether every occurrence in the superclass mustparticipate as a member of a subclass.May be mandatory (i.e., every entity occurrence in thesuperclass must be a member of a subclass) or optional (i.e.,any entity occurrence in the superclass need not belong to anyof the subclasses) .

Disjoint constraint:Describes the relationship between members of the subclassesand indicates whether it is possible for a member of asuperclass to be a member of one, or more than one, subclass.Applies only if the superclass has more than one subclass.May be disjoint (i.e., if subclasses are pair-wise disjoint, Or) ornondisjoint (i.e., if some of the subclasses are non-disjoint,And).

Dr Muhammad Sulaiman Khan COMP102: Introduction to Databases, 13

Page 14: COMP102: Introduction to Databases, 13cgi.csc.liv.ac.uk/~khan/comp102/lecture15-2011.pdf · The Enhanced Entity Relationship (EER) ... translating EER diagram into tables ... Dr Muhammad

Example: Vehicle entity into vehicle types (UML diagram):

Dr Muhammad Sulaiman Khan COMP102: Introduction to Databases, 13

Page 15: COMP102: Introduction to Databases, 13cgi.csc.liv.ac.uk/~khan/comp102/lecture15-2011.pdf · The Enhanced Entity Relationship (EER) ... translating EER diagram into tables ... Dr Muhammad

Constraints on specialization/generalization

There are four categories of constraints of specialization andgeneralization:

mandatory and disjoint;

optional and disjoint;

mandatory and nondisjoint;

optional and nondisjoint.

Dr Muhammad Sulaiman Khan COMP102: Introduction to Databases, 13

Page 16: COMP102: Introduction to Databases, 13cgi.csc.liv.ac.uk/~khan/comp102/lecture15-2011.pdf · The Enhanced Entity Relationship (EER) ... translating EER diagram into tables ... Dr Muhammad

Creating tables to represent specialization/generalization (i.e.,translating EER diagram into tables (relational model):

For each superclass/subclass relationship in EER model,designate the superclass as the parent entity (table) and thesubclass as the child entity (table).

How many tables is required to represent such relationshipdepends on the participation and disjoint constraints.

Dr Muhammad Sulaiman Khan COMP102: Introduction to Databases, 13

Page 17: COMP102: Introduction to Databases, 13cgi.csc.liv.ac.uk/~khan/comp102/lecture15-2011.pdf · The Enhanced Entity Relationship (EER) ... translating EER diagram into tables ... Dr Muhammad

Creating tables to represent specialization/generalization, contd.

Although, the table in the previous slide presents only generalguidelines of how to model the specialization/generalizationrelationships with tables, there are further factors that influencethe final modeling:

whether the subclasses are involved in distinct relationships;

the number of attributes that are distinct to each subclass;

the relative number of entity occurrences represented by thesuperclass and by each subclass.

Note: Compare these issues with modeling ER 1:1 relationshipwith optional participation on both sides as tables that wediscussed in Lecture 12.

Dr Muhammad Sulaiman Khan COMP102: Introduction to Databases, 13

Page 18: COMP102: Introduction to Databases, 13cgi.csc.liv.ac.uk/~khan/comp102/lecture15-2011.pdf · The Enhanced Entity Relationship (EER) ... translating EER diagram into tables ... Dr Muhammad

Example: Tables representing Staff and the Branch entities:

Based on previous example with Staff superclass and subclassesManager, SalesPersonnel, and Secretary;constraints are { Optional, Nondisjoint (And) }:

Dr Muhammad Sulaiman Khan COMP102: Introduction to Databases, 13

Page 19: COMP102: Introduction to Databases, 13cgi.csc.liv.ac.uk/~khan/comp102/lecture15-2011.pdf · The Enhanced Entity Relationship (EER) ... translating EER diagram into tables ... Dr Muhammad

Example: Tables representing the Vehicle entity:

Based on previous example with Vehicle superclass and subclassesVan, Bus, and Car; constraints are { Mandatory, Disjoint (Or) }:

Dr Muhammad Sulaiman Khan COMP102: Introduction to Databases, 13