36
Lecture 7 Enhanced Entity- Relationship Modelling & Advanced Normalisation

Lecture 7 Enhanced Entity-Relationship Modelling & Advanced Normalisation

Embed Size (px)

Citation preview

Page 1: Lecture 7 Enhanced Entity-Relationship Modelling & Advanced Normalisation

Lecture 7

Enhanced Entity-Relationship Modelling

&

Advanced Normalisation

Page 2: Lecture 7 Enhanced Entity-Relationship Modelling & Advanced Normalisation

2

Lecture 7 – Part 1

Enhanced Entity-Relationship Modelling

Page 3: Lecture 7 Enhanced Entity-Relationship Modelling & Advanced Normalisation

3

Introduction

• Limitations of basic concepts of the ER model and requirements to represent more complex applications using additional data modelling concepts.

• Most useful additional data modelling concepts of Enhanced ER (EER) model called:– specialization/generalization;

– aggregation;

– composition.

• EER diagram using UML.

Page 4: Lecture 7 Enhanced Entity-Relationship Modelling & Advanced Normalisation

4

Specialization / Generalization

• Superclass– An entity type that includes one or more distinct subgroupings

of its occurrences.

• Subclass– A distinct subgrouping of occurrences of an entity type.

• Superclass/subclass relationship is one-to-one. • Superclass may contain overlapping or distinct

subclasses. • Not all members of a superclass need be a

member of a subclass.

Page 5: Lecture 7 Enhanced Entity-Relationship Modelling & Advanced Normalisation

5

Specialization / Generalization

• Attribute Inheritance– An entity in a subclass represents same ‘real

world’ object as in superclass, and may possess subclass-specific attributes, as well as those associated with the superclass.

Page 6: Lecture 7 Enhanced Entity-Relationship Modelling & Advanced Normalisation

6

Specialization / Generalization

• Specialization – Process of maximizing differences between

members of an entity by identifying their distinguishing characteristics.

• Generalization– Process of minimizing differences between

entities by identifying their common characteristics.

Page 7: Lecture 7 Enhanced Entity-Relationship Modelling & Advanced Normalisation

7

Specialization/Generalization - Example

• Doctor(doc_staffno, roomno, telno, training_hospital, date_qualified)

• Surgeon(sur_staffno, roomno, telno, training_hospital, date_qualified, speciality)

• Consultant(con_staffno, roomno, telno, training_hospital, date_qualified, specialism)

DoctorSurgeon Consultantis_surgeon is_consultant

Inefficient Representation

Page 8: Lecture 7 Enhanced Entity-Relationship Modelling & Advanced Normalisation

8

Specialization/Generalization – ExampleBachman’s Notation

Doctor

Surgeon Consultant

speciality specialism

doc_staffno

roomno

Page 9: Lecture 7 Enhanced Entity-Relationship Modelling & Advanced Normalisation

9

Specialization/Generalization – ExampleUML Notation

Doctor

Surgeon Consultant

speciality specialism

StaffnoRoomnoTelnoTraining_hospitalDate_qualified

Page 10: Lecture 7 Enhanced Entity-Relationship Modelling & Advanced Normalisation

10

AllStaff Relation Holding Details of all Staff

Page 11: Lecture 7 Enhanced Entity-Relationship Modelling & Advanced Normalisation

11

Specialization/Generalization of Staff Entity into Subclasses Representing Job Roles

Page 12: Lecture 7 Enhanced Entity-Relationship Modelling & Advanced Normalisation

12

Specialization/Generalization of Staff Entity into Job Roles and Contracts of Employment

Page 13: Lecture 7 Enhanced Entity-Relationship Modelling & Advanced Normalisation

13

EER Diagram with Shared Subclass and Subclass with its own Subclass

Page 14: Lecture 7 Enhanced Entity-Relationship Modelling & Advanced Normalisation

14

Constraints on Specialization / Generalization

• Two constraints that may apply to a specialization/generalization: – participation constraints, – disjoint constraints.

• Participation constraint– Determines whether every member in superclass must

participate as a member of a subclass.

– May be mandatory or optional.

Page 15: Lecture 7 Enhanced Entity-Relationship Modelling & Advanced Normalisation

15

Constraints on Specialization / Generalization

• Disjoint constraint – Describes relationship between members of the

subclasses and indicates whether member of a superclass can be a member of one, or more than one, subclass.

– May be disjoint or nondisjoint.

Page 16: Lecture 7 Enhanced Entity-Relationship Modelling & Advanced Normalisation

16

Constraints on Specialization / Generalization

• There are four categories of constraints of specialization and generalization:– mandatory and disjoint;– optional and disjoint;– mandatory and nondisjoint;– optional and nondisjoint.

Page 17: Lecture 7 Enhanced Entity-Relationship Modelling & Advanced Normalisation

17

DreamHome Example - Staff Superclass with Supervisor and Manager Subclasses

Page 18: Lecture 7 Enhanced Entity-Relationship Modelling & Advanced Normalisation

18

DreamHome Example - Owner Superclass with PrivateOwner and BusinessOwner Subclasses

Page 19: Lecture 7 Enhanced Entity-Relationship Modelling & Advanced Normalisation

19

Converting Superclass/Subclass Relationship into Relational Model

Page 20: Lecture 7 Enhanced Entity-Relationship Modelling & Advanced Normalisation

20

Converting Superclass/Subclass Relationship into Relational Model

• Option 1 – Mandatory, Nondisjoint (And)AllOwner (ownerNo, address, telNo, fName, lName, bName, bType,contactName, pOwnerFlag, bOwnerFlag)

{Mandatory, And}

Page 21: Lecture 7 Enhanced Entity-Relationship Modelling & Advanced Normalisation

21

Converting Superclass/Subclass Relationship into Relational Model

• Option 2 – Optional, Nondisjoint (And)Owner (ownerNo, address, telNo)

OwnerDetails (ownerNo*, fName, lName, bName, bType, contactName,

pOwnerFlag, bOwnerFlag)

{Optional, And}

Page 22: Lecture 7 Enhanced Entity-Relationship Modelling & Advanced Normalisation

22

Converting Superclass/Subclass Relationship into Relational Model

• Option 3 – Mandatory, Disjoint (Or)PrivateOwner (ownerNo, fName, lName, address, telNo)

BusinessOwner (ownerNo, bName, bType, contactName, address, telNo)

{Mandatory, Or}

Page 23: Lecture 7 Enhanced Entity-Relationship Modelling & Advanced Normalisation

23

Converting Superclass/Subclass Relationship into Relational Model

• Option 4 – Optional, Disjoint (Or)Owner (ownerNo, address, telNo)

PrivateOwner (ownerNo*, fName, lName)

BusinessOwner (ownerNo*, bName, bType, contactName)

{Optional, Or}

Page 24: Lecture 7 Enhanced Entity-Relationship Modelling & Advanced Normalisation

24

Aggregation

• Represents a ‘has-a’ or ‘is-part-of’ relationship between entity types, where one represents the ‘whole’ and the other ‘the part’.

Page 25: Lecture 7 Enhanced Entity-Relationship Modelling & Advanced Normalisation

25

Examples of Aggregation

Page 26: Lecture 7 Enhanced Entity-Relationship Modelling & Advanced Normalisation

26

Composition

• Specific form of aggregation that represents an association between entities, where there is a strong ownership and coincidental lifetime between the ‘whole’ and the ‘part’.

Page 27: Lecture 7 Enhanced Entity-Relationship Modelling & Advanced Normalisation

27

Example of Composition

Page 28: Lecture 7 Enhanced Entity-Relationship Modelling & Advanced Normalisation

28

Lecture 7 – Part 2

Advanced Normalization

Page 29: Lecture 7 Enhanced Entity-Relationship Modelling & Advanced Normalisation

29

Boyce–Codd Normal Form (BCNF)

• BCNF - A relation is in BCNF if and only if every determinant (of a functional dependency) is a candidate key.

• Violation of BCNF is quite rare. • Potential to violate BCNF may occur in a

relation that:– contains two (or more) composite candidate keys; or– the candidate keys overlap (i.e. have at least one

attribute in common).

Page 30: Lecture 7 Enhanced Entity-Relationship Modelling & Advanced Normalisation

30

BCNF - Example

clientNo interviewDate interviewTime staffNo roomNo

CR76 13-May-05 10:30 SG5 G101

CR56 13-May-05 12:00 SG5 G101

CR74 13-May-05 12:00 SG37 G102

CR56 1-Jul-05 10:30 SG5 G102

The relation ClientInterview stores information on client interviews by members of staff.

The relation has 3 candidate keys: (clientNo, interviewDate), (staffNo, interviewDate, interviewTime), and (roomNo, interviewDate, interviewTime).The 3 composite candidate keys share a common attribute interviewDate

Page 31: Lecture 7 Enhanced Entity-Relationship Modelling & Advanced Normalisation

31

BCNF - Example

We select (clientNo, interviewDate) to be the primary key:ClientInterview (clientNo, interviewDate, interviewTime, staffNo, roomNo)

The relation has the following functional dependencies: Fd1: clientNo, interviewDate interviewTime, staffNo, roomNoFd2: staffNo, interviewDate, interviewTime clientNoFd3: roomNo, interviewDate, interviewTime staffNo, clientNoFd4: staffNo, interviewDate roomNo

The determinants in Fd1, Fd2 and Fd3 are candidate keys but Fd4 is not. This means the relation is not in BCNF. As a consequence the relation may suffer from update anomalies. For example, to change the roomNo for staff SG5 on the 13-May-05 we must update two rows otherwise we will have inconsistency in the table.

Page 32: Lecture 7 Enhanced Entity-Relationship Modelling & Advanced Normalisation

32

BCNF - Example

• To transform the relation to BCNF we must remove the violating functional dependency by splitting the original relation into two new relations:

Interview (clientNo, interviewDate, interviewTime, staffNo)

StaffRoom (staffNo, interviewDate, roomNo)

Note: in creating these 2 BCNF relations we have lost Fd3, as the

determinant for this dependency is no longer in the same relation.

The decision of whether to stop at 3NF or BCNF is dependent on

the amount of redundancy resulting from the presence of Fd4 and

the significance of the loss of Fd3.

Page 33: Lecture 7 Enhanced Entity-Relationship Modelling & Advanced Normalisation

33

Fourth Normal Form (4NF)

• MVD: Dependency between attributes (for example, A, B, and C) in a relation, such that for each value of A there is a set of values for B and a set of values for C. However, set of values for B and C are independent of each other:

A B

A C

• Possible existence of MVDs in a relation is due to 1NF and can result in data redundancy.

Page 34: Lecture 7 Enhanced Entity-Relationship Modelling & Advanced Normalisation

34

Fourth Normal Form (4NF)

• MVD can be trivial or nontrivial.

– MVD A B in relation R is defined as being trivial if (a) B is a subset of A or (b) A B = R.

– MVD is defined as being nontrivial if neither (a) nor (b) are satisfied.

– Trivial MVD does not specify a constraint on a relation, while a nontrivial MVD does specify a constraint.

Page 35: Lecture 7 Enhanced Entity-Relationship Modelling & Advanced Normalisation

35

Fourth Normal Form (4NF)

• 4NF: a relation that is in BCNF and contains no nontrivial MVDs.

• The normalisation involves the removal of the MVD from the relation and placing the attribute(s) in a new relation along with a copy of the determinant(s).

Page 36: Lecture 7 Enhanced Entity-Relationship Modelling & Advanced Normalisation

36

4NF - Example