Top Banner
CIT 381 ER Modeling Difficulties - categories - generalization - three-way relationships
14

CIT 381 ER Modeling Difficulties - categories - generalization - three-way relationships.

Dec 19, 2015

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: CIT 381 ER Modeling Difficulties - categories - generalization - three-way relationships.

CIT 381

ER Modeling Difficulties

-categories-generalization-three-way relationships

Page 2: CIT 381 ER Modeling Difficulties - categories - generalization - three-way relationships.

Relationship types

From ER Studio documentation

Page 3: CIT 381 ER Modeling Difficulties - categories - generalization - three-way relationships.

Categories and roles Suppose that we have employees with key ssn

Some of the employees are staff and are paid hourly

Other employees are paid a salary

The can be handled easily using weak entities

Page 4: CIT 381 ER Modeling Difficulties - categories - generalization - three-way relationships.

Categories with weak entities

Example from bighitvideo database.

Note the implicit ‘Z’ - a one-to-one relationship.

Page 5: CIT 381 ER Modeling Difficulties - categories - generalization - three-way relationships.

Categories - more formal

You do not need to use this notation. We mention it since you may see it.

Page 6: CIT 381 ER Modeling Difficulties - categories - generalization - three-way relationships.

Generalization Suppose we have three entities: company, pilot, and aircraft

company has key compId (an int) pilot has key license (a char) An aircraft can be owned by either a company or a pilot (but not both)

How do we model this? It’s hard!

Page 7: CIT 381 ER Modeling Difficulties - categories - generalization - three-way relationships.

Aircraft owner problem

We need to ensure that one of the foreign keys is null and the other is not null.

Page 8: CIT 381 ER Modeling Difficulties - categories - generalization - three-way relationships.

An attempt: introduce an owner

Now how to connect owner to the owning entities?

Page 9: CIT 381 ER Modeling Difficulties - categories - generalization - three-way relationships.

Connect the owner

Still kind of strange, but still better. Must ensure that each ownerId appears just once as either a pilot or a company. (Can be modeled as a complete exclusive category.)

Page 10: CIT 381 ER Modeling Difficulties - categories - generalization - three-way relationships.

Subtleties with 3-way relationships

Well, we don’t really have 3-way relationships, because we create bridge tables.

But think of entities class, book, instructor

Page 11: CIT 381 ER Modeling Difficulties - categories - generalization - three-way relationships.

Three-way example

Consider where the books used for a class depend on the instructor:

classNum instrName title

CIT381 Chris Big DB

CIT381 Craig Good DB

CIT381 Craig MySQL Bk

CIS313 Chris Algorithms

Page 12: CIT 381 ER Modeling Difficulties - categories - generalization - three-way relationships.

Bridge table has three keys

Page 13: CIT 381 ER Modeling Difficulties - categories - generalization - three-way relationships.

Small change At most one book per class. Then title not part of key.

Question:Should the dotted line be mandatory or optional?

Page 14: CIT 381 ER Modeling Difficulties - categories - generalization - three-way relationships.

Another change Several books per class, but books used do not depend on the instructor.

This design avoids duplication. Why?