Database Design (3) IS 240 – Database Management Lecture #12 – 2004-03-30 Prof. M. E. Kabay,...

Preview:

Citation preview

Database Design (3)

IS 240 – Database ManagementLecture #12 – 2004-03-30

Prof. M. E. Kabay, PhD, CISSP

Norwich University

mkabay@norwich.edu

2

Topics

SubtypesTreesNetworksBill of MaterialsSurrogate KeysNull Values

3

Subtypes (1)

Consider a currency-trading operationThere’s a counter for walk-in anonymous clients

Need only date, time, currency_in, rate, currency_out, fee; customer_ID is set to 0.

People who use the service often can become regular customers and receive a monthly statement of all transactionsIn addition to info above, need name,

customer_ID, address etc.Corporate customers have a corporate_ID and a

list of authorized usersTheir monthly report includes a total_fees field

that gives the aggregated total for all users

4

Subtypes (2)

Show diagrams for the relations above as subtypes of customer

Why not lump all the customers into a single relation?

6

Subtypes (3)

Show the tables you could create to represent the situation described above

8

Trees

Many systems involve hierarchical 1:N relationsAdministrative hierarchies

Department, directorate, division, unit…Polychotomous classifications of various

kindsKingdom, phylum, class, order, family…

Every element in tree is a nodeTop level of classification: rootParent nodes have child nodes in a branchA child node can have one and only one

parent

9

Trees (cont’d)How can you represent the relationships in a

tree? Consider a system for tracking students in college dormitories:

College

Dormitory

Floor

Room

Student

10

Networks

In simple networks an entity may have more than one parent

The parent entities have M:N relations to the child entities

Give an example of a network using doctors, nurses and patients in a health-care system

11

Network: Doctors, Nurses, Patients

Draw the health-care example you have developed

13

Bill of Materials

In manufacturing systems, many components may contain many partsTrying to model these relations caused

headaches in the early years of DBMS design

Why?Solution: treat the relation as recursive

Every element is described in its own tableEvery relationship is described by the

container and the contained elementsStructure thus very simple – now draw it!

14

Bill of Materials Design

16

Surrogate Keys

To link two relations in a relationship table, we need unique IDs

What if the key we use when designing a relation is not in fact unique?What happens to our tables?

What if the keys we use are very long?What about efficiency?

17

Surrogate Keys (cont’d)

DBMS can supply a system-assigned unique identifierTypically a simple numberTakes little roomEasy to use in indexingPrevents duplication of keys

How do we use these unique identifiers in our relationship table?Show an example with doctor/patient

What is the main disadvantage of this surrogate key technique?

18

Null Values

What are the possible meanings of a field that has not been filled in by a user (a null or empty field)?

For inappropriate values (e.g., gender-specific attributes), should you always use subtypes?

Can also assign a blank value ab initioChange blank to N/A or UNKNOWN if

necessaryMust handle these values in code (why?)

19

HOMEWORKReview Chapter 6 of Kroenke

Prepare for next class by applying SQ3R to chapter 8 of Kroenke.

REQUIRED: By Tuesday 6 April, complete and hand in answers to review questions 6.25 through 6.36 for 24 points.

OPTIONAL: Also by Tuesday 6 April, for an extra 2 points each, complete any or all of Projects 6A, 6B or 6C.

(More homework possibilities for extra credit on next page)

20

HOMEWORK (cont’d)

For a 2 extra points each, complete any or all of the FiredUp projects A through D on pp 180-181. To submit B you must first do ATo submit D you must first do C

21

DISCUSSION

Recommended