You are on page 1of 37

Database Design

Chapter 04

Supertypes and Subtypes


Supertypes and Subtypes

CHANGE EXAMPLE TO COLLEGE


USE EMPLOYEE FOR MAIN STREET PLUMBING
Supertypes & Subtypes
• Supertype:
– An entity type that has a relationship (parent to child relationship) with
one or more subtypes
– Contains attributes that are common to its subtypes
• Subtype:
– Subgroups of the supertype entity
– Have unique attributes that are usually different from each subtype
• Primary keys of supertypes and subtypes are always identical
Supertypes & Subtypes
• Supertype: A generic entity
that has a relationship with one
or more subtypes

• Subtype: A subgrouping of
entities within a supertype
entity
Examples of Supertypes and Subtypes
• PAYMENT entity (check, cash, credit card)

• VEHICLE entity (car, truck, motorcycle, RV, boat)

• PEOPLE entity (faculty, student, staff)

5
Supertypes and Subtypes

• Typically associate "choices" or "classifications" with supertypes


and subtypes

6
College Supertype/Subtype Example
• Create an ER diagram to store data about people at a college
• Assumptions:
– A student may have only one major
– Store only the highest degree earned by a faculty member
– The status column of staff members refers to whether they are part-
time or full-time
– The database will not store data about any other category of people
– A person can belong to more than one group at a time

7
College Supertype/Subtype Example

8
Step 1: Identify entities

9
Step 2: Identify attributes and UID

10
Step 3: Identify common attributes

11
Step 4: Create Supertype/Subtype Hierarchy

12
Box-in-Box Presentation

13
Non-Box-in-Box Presentation

14
Inheritance - attributes
• Subtype entities inherit all
attributes of the supertype

• The subtypes HOURLY, SALARY,


and CONSULTANT inherit the
attributes employee_id,
employee_name, address, and
date_hired from the EMPLOYEE
supertype
Subtype Attributes
• Each subtype entity has its own
attributes that are distinct from
the other subtype entities
Inheritance - Relationships
• Subtypes inherit all relationships of the supertype
Inheritance - Relationships
• Subtypes can have relationships of there own
Inheritance - instances
• An instance of a subtype is also
an instance of the supertype
Exhaustive Subtype Rule
• Exhaustive: No other category
exists other than those defined
by the subtypes

• It may be good practice to


include an OTHER subtype to
make sure that the subtypes
are exhaustive

20
Exclusive or Non-Overlapping Subtype Rule
• Each supertype instance can be
related to only one subtype
instance

• Every instance of EMPLOYEE is


also an instance of HOURLY,
SALARY, and/or CONSULTANT
Mutually Exclusive Subtype Rule
• Each instance of a supertype is an instance of one and only one
subtype

22
Mutually Exclusive
• A vehicle is "classified" into subtypes
• Mutually Exclusive: every instance of VEHICLE must be an
instance of only ONE of the subtypes

23
Nested Subtypes
• Subtypes can be nested

24
Supertypes and Subtypes
• A subtype:
– inherits all attributes of the supertype
– inherits all relationships of the supertype
– have attributes or relationships that are different from other subtypes
– is drawn within the supertype
– never exists alone
– may have subtypes of its own

25
Supertypes and Subtypes
• Each subtype has an attribute that the other subtypes may not
have, and can't go in the supertype because all of them don't
"need" that attribute
• If an entity has a subtype, there should always be at least a
second subtype

26
Example
• Both outpatients and resident patients are cared for by a
physician
• Only resident patients are assigned to a bed

27
The End

28
Business Rules
• One of the primary goals of data modeling is to ensure that all
pieces of information that are required to run a business are
recognized

• Business rules become constraints when database is created.

29
Business Rules
• Structural rules indicate
– The type of data to be stored (attributes)
– How the data elements interrelate (relationships)
– Rules implemented in an ERD
• Procedural rules indicate
– Workflow processes
– Business processes
– Rules implemented by programming

30
Structural or Procedural Rule?
• All teachers must possess a valid teaching certificate

• Structural
– Type of data to be stored (attribute)

31
Structural or Procedural Rule?
• All orders at a restaurant must be handled by staff. There is no
self-service ordering system

• Structural Rule
– How the data elements interrelate (relationships)

32
Procedural Rule
• Students must have studied algebra and geometry in order to
sign up for trigonometry
– Could you represent this in the ERD?
 No
– How would you implement this with programming?
 When a student tries to sign up for a class, a program checks to see if the
student has taken the pre-requisite

33
Procedural Rule
– If the student had taken the pre-requisite(s), what is another business
rule that a school may want in this scenario?
 Did the student pass the pre-requisite(s)

34
Documenting Procedural Rules
• In the process of developing a conceptual data model, not all
business rules can be modeled
• Some rules must be implemented by programming:
– Any employee whose overtime exceeds 10 hours per week must be
paid 1.5 times the hourly rate

– Customers whose account balances are 90 days overdue will not be


permitted to charge additional orders

35
Inclusive or Overlapping Subtype Rule
• A supertype instance may belong to more than one subtype
category
• In the example, Dana Hewitt is both a STUDENT and STAFF

36
The End

37

You might also like