• No results found

Subtyping ExplainedSubtyping Explained

In document Data Modeling by Steve Hoberman (Page 34-37)

Subtyping Explained

Subtyping groups the common

Subtyping groups the common data elements and relationships of entities, while retaining what isdata elements and relationships of entities, while retaining what is unique within each entity. Subtyping is an excellent way of communicating that certain concepts unique within each entity. Subtyping is an excellent way of communicating that certain concepts are very similar.

are very similar.

In our ice cream example, we are told that an ice cream cone and ice cream cup can each contain In our ice cream example, we are told that an ice cream cone and ice cream cup can each contain many scoops of ice cream,

many scoops of ice cream, as illustrated in Figure 6.5.as illustrated in Figure 6.5.

Figure 6.5: Ice cream example before subtyping Figure 6.5: Ice cream example before subtyping

Each Ice Cream Cone can hold one or many Ice Cream Scoops.Each Ice Cream Cone can hold one or many Ice Cream Scoops.

Each Ice Cream Scoop must be held in one Ice Cream Cone.Each Ice Cream Scoop must be held in one Ice Cream Cone.

Each Ice Cream Cup can hold one or many Ice Cream Scoops.Each Ice Cream Cup can hold one or many Ice Cream Scoops.

Each Ice Cream Scoop must be held in one Ice Cream Cup.Each Ice Cream Scoop must be held in one Ice Cream Cup.

Rather than repeat the relationship to Ice Cream Scoop twice, we can introduce subtyping, as Rather than repeat the relationship to Ice Cream Scoop twice, we can introduce subtyping, as shown in Figure 6.6.

shown in Figure 6.6.

Figure 6.6: Ice cream example after subtyping Figure 6.6: Ice cream example after subtyping

Each Ice Cream Container can hold one or many Ice Cream Scoops.Each Ice Cream Container can hold one or many Ice Cream Scoops.

Each Ice Cream Scoop must be held in one Ice Cream Container.Each Ice Cream Scoop must be held in one Ice Cream Container.

Each Ice Cream Container can be either an Ice Cream Cone or an Ice Cream Scoop.Each Ice Cream Container can be either an Ice Cream Cone or an Ice Cream Scoop.

Each Ice Cream Cone is an Ice Cream Container.Each Ice Cream Cone is an Ice Cream Container.

Each Ice Cream Cup is an Ice Cream Container.Each Ice Cream Cup is an Ice Cream Container.

The subtyping relationship implies that all of the

The subtyping relationship implies that all of the properties from the supertype are inherited byproperties from the supertype are inherited by the subtype. Therefore, there is an

the subtype. Therefore, there is an implied relationship from Ice Cream Cone to Ice implied relationship from Ice Cream Cone to Ice CreamCream Scoop as well as Ice Cream Cup to Ice Cream Scoop. Not only does subtyping reduce Scoop as well as Ice Cream Cup to Ice Cream Scoop. Not only does subtyping reduce

redundancy on a data model, it makes it easier to communicate similarities across what otherwise redundancy on a data model, it makes it easier to communicate similarities across what otherwise would appear to be distinct and separate concepts.

would appear to be distinct and separate concepts.

Exercise 6: Reading a Model Exercise 6: Reading a Model

1.

1. Practice reading the relationships in this model. See the Appendix for my answers.Practice reading the relationships in this model. See the Appendix for my answers.

Answers Answers 1.

1. Recall the model:Recall the model:

Each Employee may process one or many Transactions.

Each Employee may process one or many Transactions.

Each Transaction must be processed by one Employee.

Each Transaction must be processed by one Employee.

Each Transaction may be either

Each Transaction may be either an Order, Credit, or Debit.an Order, Credit, or Debit.

Each Order is a Transaction.

Each Order is a Transaction.

Each Credit is a Transaction.

Each Credit is a Transaction.

Each Debit is a Transaction.

Each Debit is a Transaction.

Each Employee may contact one or many Customers.

Each Employee may contact one or many Customers.

Each Customer must be contacted by one Employee.

Each Customer must be contacted by one Employee.

Each Customer may place one or many Orders.

Each Customer may place one or many Orders.

Each Order must be placed by one Customer.

Each Order must be placed by one Customer.

Each Order may contain one or many Order Lines.

Each Order may contain one or many Order Lines.

Each Order Line must belong to one Order.

Each Order Line must belong to one Order.

Each Product may appear on one or many Order Lines.

Each Product may appear on one or many Order Lines.

Each Order Line must reference one Product.

Each Order Line must reference one Product.

Each Product may contain one or many Products.

Each Product may contain one or many Products.

Each Product may belong to one Product.

Each Product may belong to one Product.

Key Points Key Points

A rule is visually captured on a data model by a line connecting two entities, called aA rule is visually captured on a data model by a line connecting two entities, called a relationship.

relationship.

Data rules are instructions onData rules are instructions on howhow data relate to one another. Action rules are instructions data relate to one another. Action rules are instructions on

on what to dowhat to do when data elements contain certain values. when data elements contain certain values.

Cardinality is represented by the symbols on both Cardinality is represented by the symbols on both ends of a relationship that define theends of a relationship that define the number of instances of each

number of instances of each entity that can participate in the relationship. The entity that can participate in the relationship. The threethree simple choices are zero, one, or many.

simple choices are zero, one, or many.

Labels are the verbs that aLabels are the verbs that appear on the relationship lines. Labels should be ppear on the relationship lines. Labels should be as descriptiveas descriptive as possible to retain data model p

as possible to retain data model precision.recision.

A recursive relationship is a rule that exists between instances of the same entity.A recursive relationship is a rule that exists between instances of the same entity.

Subtyping groups the common Subtyping groups the common properties of entities while retaining what is unique withinproperties of entities while retaining what is unique within each entity.

each entity.

Chapter 7: What are Keys?

Chapter 7: What are Keys?

Overview Overview

 More than o

 More than one John Doene John Doe Which is the right Customer?

Which is the right Customer?

 Recall by th  Recall by the keye key

There is a lot of data out there, but how do you sift through it all to find what you're looking There is a lot of data out there, but how do you sift through it all to find what you're looking for? That's where keys come in. Keys allow us to efficiently retrieve data, as well as navigate for? That's where keys come in. Keys allow us to efficiently retrieve data, as well as navigate from one physical table to an

from one physical table to another. This chapter defines keys and distinguishes between other. This chapter defines keys and distinguishes between thethe terms candidate, primary, and alternate keys. Surrogate keys and foreign keys and their terms candidate, primary, and alternate keys. Surrogate keys and foreign keys and their importance are also explained.

importance are also explained.

In document Data Modeling by Steve Hoberman (Page 34-37)