Keys for Relationship Sets The combination of primary keys of the participating entity sets forms a...

20
Keys for Relationship Sets The combination of primary keys of the participating entity sets forms a super key of a relationship set. (customer-id, account-number) is the super key of depositor Must consider the mapping cardinality of the relationship set when deciding the what are the candidate keys Need to consider semantics of relationship set in selecting the primary key in case of more than one candidate key 1

Transcript of Keys for Relationship Sets The combination of primary keys of the participating entity sets forms a...

Page 1: Keys for Relationship Sets The combination of primary keys of the participating entity sets forms a super key of a relationship set. – (customer-id, account-number)

Keys for Relationship Sets

The combination of primary keys of the participating entity sets forms a super key of a relationship set.

– (customer-id, account-number) is the super key of depositor

Must consider the mapping cardinality of the relationship set when deciding the what are the candidate keys

Need to consider semantics of relationship set in selecting the primary key in case of more than one candidate key

1

Page 2: Keys for Relationship Sets The combination of primary keys of the participating entity sets forms a super key of a relationship set. – (customer-id, account-number)

E-R Diagram with a Ternary Relationship

2

Page 3: Keys for Relationship Sets The combination of primary keys of the participating entity sets forms a super key of a relationship set. – (customer-id, account-number)

Design Issues

Use of entity sets vs. attributesChoice mainly depends on the structure of the enterprise being modeled, and on the semantics associated with the attribute in question.

Use of entity sets vs. relationship setsPossible guideline is to designate a relationship set to describe an action that occurs between entities

Binary versus n-ary relationship setsAlthough it is possible to replace any nonbinary (n-ary, for n > 2) relationship set by a number of distinct binary relationship sets, a n-ary relationship set shows more clearly that several entities participate in a single relationship.

Placement of relationship attributes3

Page 4: Keys for Relationship Sets The combination of primary keys of the participating entity sets forms a super key of a relationship set. – (customer-id, account-number)

Enhanced-ER (EER) Model Concepts

Includes all modeling concepts of basic ER

Additional concepts: subclasses/superclasses,

specialization/generalization, categories, attribute inheritance

The resulting model is called the enhanced-ER or Extended ER

(E2R or EER) model

It is used to model applications more completely and accurately

if needed

Page 5: Keys for Relationship Sets The combination of primary keys of the participating entity sets forms a super key of a relationship set. – (customer-id, account-number)

Specialization

Top-down design process; we designate subgroupings within an entity set that are distinctive from other entities in the set.

These subgroupings become lower-level entity sets that have attributes or participate in relationships that do not apply to the higher-level entity set.

Depicted by a triangle component labeled ISA (E.g. customer “is a” person).

Attribute inheritance – a lower-level entity set inherits all the attributes and relationship participation of the higher-level entity set to which it is linked.5

Page 6: Keys for Relationship Sets The combination of primary keys of the participating entity sets forms a super key of a relationship set. – (customer-id, account-number)

Specialization Example

6

Page 7: Keys for Relationship Sets The combination of primary keys of the participating entity sets forms a super key of a relationship set. – (customer-id, account-number)

Generalization

A bottom-up design process – combine a number of entity sets that share the same features into a higher-level entity set.

Specialization and generalization are simple inversions of each other; they are represented in an E-R diagram in the same way.

The terms specialization and generalization are used interchangeably.

7

Page 8: Keys for Relationship Sets The combination of primary keys of the participating entity sets forms a super key of a relationship set. – (customer-id, account-number)

Specialization and Generalization (Contd.)

Can have multiple specializations of an entity set based on different features.

E.g. permanent-employee vs. temporary-employee, in addition to officer vs. secretary vs. teller

Each particular employee would be – a member of one of permanent-employee or temporary-

employee, – and also a member of one of officer, secretary, or teller

The ISA relationship also referred to as superclass - subclass relationship

8

Page 9: Keys for Relationship Sets The combination of primary keys of the participating entity sets forms a super key of a relationship set. – (customer-id, account-number)

Inheritance

STAFF

SALESPERSONNEL

UnsharedAttributes

Superclass

AddressDobName

SalesArea

CarAllowance

SharedAttributes

Subclass REQUIRE CAR

UnsharedRelationship

CONTRACT COMPANY

SharedRelationship

Page 10: Keys for Relationship Sets The combination of primary keys of the participating entity sets forms a super key of a relationship set. – (customer-id, account-number)

Disjointness Constraint: – Specifies that the subclasses of the specialization must be

disjointed (an entity can be a member of at most one of the subclasses of the specialization). Specified by d (inside the circle) in EER diagram

– If not disjointed, overlap; that is the same entity may be a member of more than one subclass of the specialization. Specified by o (inside the circle) in EER diagram

Constraints on Specialization and Generalization (1)

Page 11: Keys for Relationship Sets The combination of primary keys of the participating entity sets forms a super key of a relationship set. – (customer-id, account-number)

Introduction to Databases 11

Completeness Constraint: – Total specifies that every entity in the superclass must be a

member of some subclass in the specialization/ generalization. Shown in EER diagrams by a double line

– Partial allows an entity not to belong to any of the subclasses. Shown in EER diagrams by a single line

Constraints on Specialization and Generalization (2)

Page 12: Keys for Relationship Sets The combination of primary keys of the participating entity sets forms a super key of a relationship set. – (customer-id, account-number)

Constraints on Specialization and Generalization (3)

Hence, we have four types of specialization/generalization:

– Disjoint, total

– Disjoint, partial

– Overlapping, total

– Overlapping, partial

Note: Generalization usually is total because the superclass is

derived from the subclasses.

Page 13: Keys for Relationship Sets The combination of primary keys of the participating entity sets forms a super key of a relationship set. – (customer-id, account-number)

Example of disjoint partial Specialization

Page 14: Keys for Relationship Sets The combination of primary keys of the participating entity sets forms a super key of a relationship set. – (customer-id, account-number)

Example of overlapping total Specialization

Page 15: Keys for Relationship Sets The combination of primary keys of the participating entity sets forms a super key of a relationship set. – (customer-id, account-number)

Aggregation

Consider the ternary relationship works-on, which we saw earlier

Suppose we want to record managers for tasks performed by an employee at a branch

15

Page 16: Keys for Relationship Sets The combination of primary keys of the participating entity sets forms a super key of a relationship set. – (customer-id, account-number)

Aggregation (Cont.)

Relationship sets works-on and manages represent overlapping information

– Every manages relationship corresponds to a works-on relationship– However, some works-on relationships may not correspond to any

manages relationships So we can’t discard the works-on relationship

Eliminate this redundancy via aggregation– Treat relationship as an abstract entity– Allows relationships between relationships – Abstraction of relationship into new entity

16

Page 17: Keys for Relationship Sets The combination of primary keys of the participating entity sets forms a super key of a relationship set. – (customer-id, account-number)

E-R Diagram With Aggregation

Without introducing redundancy, the following diagram represents:

An employee works on a particular job at a particular branch An employee, branch, job combination may have an associated manager

17

Page 18: Keys for Relationship Sets The combination of primary keys of the participating entity sets forms a super key of a relationship set. – (customer-id, account-number)

E-R Design Decisions

The use of an attribute or entity set to represent an object.

Whether a real-world concept is best expressed by an entity set or a relationship set.

The use of a ternary relationship versus a pair of binary relationships.

The use of specialization/generalization – contributes to modularity in the design.

The use of aggregation – can treat the aggregate entity set as a single unit without concern for the details of its internal structure.18

Page 19: Keys for Relationship Sets The combination of primary keys of the participating entity sets forms a super key of a relationship set. – (customer-id, account-number)

Case Study: Requirements for the part of the UNIVERSITY database

The database Keeps track of three types of people: employees, alumni, and students, A person can belong to one, two, or all three of these types. Each person has a name, SSN, sex, address, and birth date.

Every employee has a salary, and there are three types of employees: faculty, staff, and student assistants. Each employee belongs to exactly one of these types. For each alumnus, a record of the degree or degrees that he or she earned at the university is kept. Including the name of the degree, the year granted, and the major department. Each student has a major department.

Each faculty has a rank, whereas each staff member has a staff position. Student assistants are classified further as either research assistants of teaching assistants, and the percent of time that they work is recorded in the database. Research assistants have their research project stored, whereas teaching assistants have the current course they work on.

Students are further classified as either graduate or undergraduate, with the specific attributes degree program (M.S.,PH.D) and class (freshman, sophomore, and so on), respectively.

Page 20: Keys for Relationship Sets The combination of primary keys of the participating entity sets forms a super key of a relationship set. – (customer-id, account-number)

Specialization / Generalization Lattice Example (UNIVERSITY)