30
Database Design and Development: A Visual Approach © 2006 Prentice Hall Chapter 5 1 DATABASE DESIGN AND DEVELOPMENT: A VISUAL APPROACH Chapter 5 Advanced Database Designs Raymond Frost – John Day – Craig Van Slyke

1 Database Design and Development: A Visual Approach © 2006 Prentice Hall Chapter 5 DATABASE DESIGN AND DEVELOPMENT: A VISUAL APPROACH Chapter 5 Advanced

  • View
    216

  • Download
    0

Embed Size (px)

Citation preview

Page 1: 1 Database Design and Development: A Visual Approach © 2006 Prentice Hall Chapter 5 DATABASE DESIGN AND DEVELOPMENT: A VISUAL APPROACH Chapter 5 Advanced

Database Design and Development: A Visual Approach © 2006 Prentice Hall

Chapter 5

1

DATABASE DESIGN AND DEVELOPMENT: A VISUAL

APPROACH

Chapter 5

Advanced Database Designs

Raymond Frost – John Day – Craig Van Slyke

Page 2: 1 Database Design and Development: A Visual Approach © 2006 Prentice Hall Chapter 5 DATABASE DESIGN AND DEVELOPMENT: A VISUAL APPROACH Chapter 5 Advanced

Database Design and Development: A Visual Approach © 2006 Prentice Hall

Chapter 5

2

Recursive Relationships

Exhibit 5-1: Enrollment Database Design

Original Design of the Enrollment Database

Page 3: 1 Database Design and Development: A Visual Approach © 2006 Prentice Hall Chapter 5 DATABASE DESIGN AND DEVELOPMENT: A VISUAL APPROACH Chapter 5 Advanced

Database Design and Development: A Visual Approach © 2006 Prentice Hall

Chapter 5

3

Mentor Recursive Relationships

Exhibit 5-2: Mentor Relationships for Enrollment Database

Instructor 11 mentors instructors 22 and 33.

Instructor 33 mentors instructor 44.

Page 4: 1 Database Design and Development: A Visual Approach © 2006 Prentice Hall Chapter 5 DATABASE DESIGN AND DEVELOPMENT: A VISUAL APPROACH Chapter 5 Advanced

Database Design and Development: A Visual Approach © 2006 Prentice Hall

Chapter 5

4

Implementing a Recursive Relationship

Exhibit 5-3: Data Relationships for MentorRecursive Relationship

A foreign key (INSTRUCTOR$id) is added to the INSTRUCTOR table, which is a copy of the primary key of that same table.

Page 5: 1 Database Design and Development: A Visual Approach © 2006 Prentice Hall Chapter 5 DATABASE DESIGN AND DEVELOPMENT: A VISUAL APPROACH Chapter 5 Advanced

Database Design and Development: A Visual Approach © 2006 Prentice Hall

Chapter 5

5

ER Diagram with a Recursive Relationship

Exhibit 5-4: Enrollment Database Diagramwith Recursive Relationship

With the foreign key added, there is now a one-to-many relationship between instructors.

Page 6: 1 Database Design and Development: A Visual Approach © 2006 Prentice Hall Chapter 5 DATABASE DESIGN AND DEVELOPMENT: A VISUAL APPROACH Chapter 5 Advanced

Database Design and Development: A Visual Approach © 2006 Prentice Hall

Chapter 5

6

Bill-of-Materials

Exhibit 5-5: Bill-of-Materials Example

A bill-of-materials is a structure that shows a relationships between products.

This is a many-to-many relationship: a product can have many sub-products, and a product can be a sub-product in many larger products.

Page 7: 1 Database Design and Development: A Visual Approach © 2006 Prentice Hall Chapter 5 DATABASE DESIGN AND DEVELOPMENT: A VISUAL APPROACH Chapter 5 Advanced

Database Design and Development: A Visual Approach © 2006 Prentice Hall

Chapter 5

7

Bill-of-Materials in Table Form

Exhibit 5-6: Bill of Materials Table

Trying to represent a many-to-many recursive relationship does not work since you could not determine how many component columns would be needed, and there will be a large number of empty cells.

Page 8: 1 Database Design and Development: A Visual Approach © 2006 Prentice Hall Chapter 5 DATABASE DESIGN AND DEVELOPMENT: A VISUAL APPROACH Chapter 5 Advanced

Database Design and Development: A Visual Approach © 2006 Prentice Hall

Chapter 5

8

ER Diagram for a Many-to-Many Recursive Relationship

Exhibit 5-7: Bill-of Materials ER Diagram

As with all many-to-many relationships, a many-to-many recursive relationship is represented with an associative table.

In this case, however, the associative table is linked back to the same table (PRODUCT), with both halves of its primary key being foreign keys from the PRODUCT table.

Page 9: 1 Database Design and Development: A Visual Approach © 2006 Prentice Hall Chapter 5 DATABASE DESIGN AND DEVELOPMENT: A VISUAL APPROACH Chapter 5 Advanced

Database Design and Development: A Visual Approach © 2006 Prentice Hall

Chapter 5

9

Many-to-Many Recursive Relationship Data

Exhibit 5-8: Bill-of-Materials Database Tables

Page 10: 1 Database Design and Development: A Visual Approach © 2006 Prentice Hall Chapter 5 DATABASE DESIGN AND DEVELOPMENT: A VISUAL APPROACH Chapter 5 Advanced

Database Design and Development: A Visual Approach © 2006 Prentice Hall

Chapter 5

10

Supertype/Subtype Hierarchies

Exhibit 5-9: Equipment Entity and Data

The first four columns apply to all equipment but the last four apply to only some equipment, which results in empty cells.

Page 11: 1 Database Design and Development: A Visual Approach © 2006 Prentice Hall Chapter 5 DATABASE DESIGN AND DEVELOPMENT: A VISUAL APPROACH Chapter 5 Advanced

Database Design and Development: A Visual Approach © 2006 Prentice Hall

Chapter 5

11

Equipment Supertype/Subtype Hierarchy

Exhibit 5-10: Equipment Supertype/SubtypeHierarchy

Supertype Entity: General entity with the common field.

Subtype Entites: specialized entities with unique fields.

Partial Specialization: Instances of the supertype don’t have to belong to a subtype.

Total Specialization: Instances of the supertype must belong to a subtype.

Disjoint rule: Supertype may belong to, at most, one subtype.

Overlap rule: Supertype may belong to multiple subtypes.

Page 12: 1 Database Design and Development: A Visual Approach © 2006 Prentice Hall Chapter 5 DATABASE DESIGN AND DEVELOPMENT: A VISUAL APPROACH Chapter 5 Advanced

Database Design and Development: A Visual Approach © 2006 Prentice Hall

Chapter 5

12

Supertype/Subtype Example

Exhibit 5-11: STUDENT, FACULTY andSTAFF tables

All three tables share four common fields.

Page 13: 1 Database Design and Development: A Visual Approach © 2006 Prentice Hall Chapter 5 DATABASE DESIGN AND DEVELOPMENT: A VISUAL APPROACH Chapter 5 Advanced

Database Design and Development: A Visual Approach © 2006 Prentice Hall

Chapter 5

13

Person Supertype/Subtype Hierarchy

Step 1: Tables

Step 2: Fields and Keys

Step 3: Recognize Common Fields

- Start by identifying three different tables.

- Add the fields and designate the primary keys.

- Make sure that the fields actually store the same data for each entity.

Exhibit 5-12: Person Supertype/SubtypeHierarchy

Page 14: 1 Database Design and Development: A Visual Approach © 2006 Prentice Hall Chapter 5 DATABASE DESIGN AND DEVELOPMENT: A VISUAL APPROACH Chapter 5 Advanced

Database Design and Development: A Visual Approach © 2006 Prentice Hall

Chapter 5

14

Person Supertype/Subtype Hierarchy

Step 4: Create Supertype/Subtype Hierarchy

- Put Common fields into new table: PERSON.- The overlap rule requires adding discriminating fields

to each subtype.- Fields specific to a category are put in matching

subtypes.- Primary keys of supertype is coped into subtypes as

foreign keys.

Step 5: Determine Total/Partial Specialization and Disjoint/Overlap Rule

- Overlap Rule is in effect since a person can be in more than one subtype.

- Total Specialization is in effect since data will only be stored about these three categories.

Exhibit 5-12: Person Supertype/SubtypeHierarchy

Page 15: 1 Database Design and Development: A Visual Approach © 2006 Prentice Hall Chapter 5 DATABASE DESIGN AND DEVELOPMENT: A VISUAL APPROACH Chapter 5 Advanced

Database Design and Development: A Visual Approach © 2006 Prentice Hall

Chapter 5

15

More Complex Supertype/Subtype Example

Exhibit 5-13: Athlete/SGA Hierarchy

Subtypes not only contain different data, but can also be involved in different relationships with other tables.

Here, an athlete student subtype is involved in a relationship with a team.

Page 16: 1 Database Design and Development: A Visual Approach © 2006 Prentice Hall Chapter 5 DATABASE DESIGN AND DEVELOPMENT: A VISUAL APPROACH Chapter 5 Advanced

Database Design and Development: A Visual Approach © 2006 Prentice Hall

Chapter 5

16

Complex Design Example:Summer Reading Fun

Exhibit 5-14: Summer Reading Fun Step-by-Step Design

Step 1: Tables

- The problem statement refers to five entities: students, books, skills, fiction books and non-fiction books.

Page 17: 1 Database Design and Development: A Visual Approach © 2006 Prentice Hall Chapter 5 DATABASE DESIGN AND DEVELOPMENT: A VISUAL APPROACH Chapter 5 Advanced

Database Design and Development: A Visual Approach © 2006 Prentice Hall

Chapter 5

17

Complex Design Example:Summer Reading Fun

Step 2: Relationships

- Fiction and Non-fiction are subtypes of books.

- Since there are no other types of books, we have total specialization.

- The disjoint rule is in effect since a book cannot be both fiction and non-fiction.

- A student has many skills and a skill is related to many students.

- A student reads many books and a book is read by many students.

- A book can be used to develop many skills and a skill can be developed in many books.

Exhibit 5-14: Summer Reading Fun Step-by-Step Design

Page 18: 1 Database Design and Development: A Visual Approach © 2006 Prentice Hall Chapter 5 DATABASE DESIGN AND DEVELOPMENT: A VISUAL APPROACH Chapter 5 Advanced

Database Design and Development: A Visual Approach © 2006 Prentice Hall

Chapter 5

18

Complex Design Example:Summer Reading Fun

Step 3: Resolve Many-to-Many Relationships

- Associative Entities are created to resolve the many-to-many relationships.

- There is also a many-to-many recursive relationship between skills: some skills are related to other skills as prerequisites.

- The recursive relationship between skills is resolved with the PREREQ associative entity.

Exhibit 5-14: Summer Reading Fun Step-by-Step Design

Page 19: 1 Database Design and Development: A Visual Approach © 2006 Prentice Hall Chapter 5 DATABASE DESIGN AND DEVELOPMENT: A VISUAL APPROACH Chapter 5 Advanced

Database Design and Development: A Visual Approach © 2006 Prentice Hall

Chapter 5

19

Complex Design Example:Summer Reading Fun

Step 4: Fields

- The fields identified in the problem statement are added to the tables.

Exhibit 5-14: Summer Reading Fun Step-by-Step Design

Page 20: 1 Database Design and Development: A Visual Approach © 2006 Prentice Hall Chapter 5 DATABASE DESIGN AND DEVELOPMENT: A VISUAL APPROACH Chapter 5 Advanced

Database Design and Development: A Visual Approach © 2006 Prentice Hall

Chapter 5

20

Complex Design Example:Summer Reading Fun

Step 5: Keys

- Primary keys are created for STUDENT, SKILL, and BOOK.

- Primary keys from tables related to associative entities are copied into the associative tables as foreign keys: the pair of foreign keys becomes the primary key of the associative tables.

- The primary key in the BOOK supertype table is copied into the subtype tables as foreign keys, which also serve as the primary keys of those tables.

Exhibit 5-14: Summer Reading Fun Step-by-Step Design

Page 21: 1 Database Design and Development: A Visual Approach © 2006 Prentice Hall Chapter 5 DATABASE DESIGN AND DEVELOPMENT: A VISUAL APPROACH Chapter 5 Advanced

Database Design and Development: A Visual Approach © 2006 Prentice Hall

Chapter 5

21

Complex Design Example:Summer Reading Fun

Data Types

Exhibit 5-15: Summer Reading Fun ER DiagramWith Data Types

Page 22: 1 Database Design and Development: A Visual Approach © 2006 Prentice Hall Chapter 5 DATABASE DESIGN AND DEVELOPMENT: A VISUAL APPROACH Chapter 5 Advanced

Database Design and Development: A Visual Approach © 2006 Prentice Hall

Chapter 5

22

Complex Design:Swampland Real Estate

Exhibit 5-16: Swampland Real Estate Step-by-Step Design

Step 1: Tables

- The problem statement refers to seven entities: property, agency, area, outlet, client and the single-family and condo property types.

Page 23: 1 Database Design and Development: A Visual Approach © 2006 Prentice Hall Chapter 5 DATABASE DESIGN AND DEVELOPMENT: A VISUAL APPROACH Chapter 5 Advanced

Database Design and Development: A Visual Approach © 2006 Prentice Hall

Chapter 5

23

Complex Design:Swampland Real Estate

Step 2: Relationships

- Clients are related to properties in two ways: as a buyer and as a seller.

- Singlefamily and condo are subtypes of books.

- Since there are other types of property, we have partial specialization.

- The disjoint rule is in effect since a property cannot be both single family and condo.

- Clients can also refer other clients to the agency, so there is a recursive relationship between clients.

Exhibit 5-16: Swampland Real Estate Step-by-Step Design

Page 24: 1 Database Design and Development: A Visual Approach © 2006 Prentice Hall Chapter 5 DATABASE DESIGN AND DEVELOPMENT: A VISUAL APPROACH Chapter 5 Advanced

Database Design and Development: A Visual Approach © 2006 Prentice Hall

Chapter 5

24

Complex Design:Swampland Real Estate

Step 3: Resolve Many-to-Many Relationships

- The many-to-many relationship between properties and outlets is resolved by adding the PROPERTYOUTLET associative table.

Exhibit 5-16: Swampland Real Estate Step-by-Step Design

Page 25: 1 Database Design and Development: A Visual Approach © 2006 Prentice Hall Chapter 5 DATABASE DESIGN AND DEVELOPMENT: A VISUAL APPROACH Chapter 5 Advanced

Database Design and Development: A Visual Approach © 2006 Prentice Hall

Chapter 5

25

Complex Design:Swampland Real Estate

Step 4: Fields

- The fields identified in the problem statement are added to the tables.

Exhibit 5-16: Swampland Real Estate Step-by-Step Design

Page 26: 1 Database Design and Development: A Visual Approach © 2006 Prentice Hall Chapter 5 DATABASE DESIGN AND DEVELOPMENT: A VISUAL APPROACH Chapter 5 Advanced

Database Design and Development: A Visual Approach © 2006 Prentice Hall

Chapter 5

26

Complex Design:Swampland Real Estate

Step 5: Keys- Each one-to-many relationship is

represented by duplicating the primary key from the one side of the relationship into the table on the many side as a foreign key.

- The primary keys of the tables linked to the associative are duplicated into the associate table as foreign keys.

- These two foreign keys are combined with the ad date to be the primary key of the associative table.

- The client recursive relationship is resolved by duplicating the primary key into the same table as a foreign key.

- The primary key in the PROPERTY supertype table is copied into the subtype tables as foreign keys, which also serve as the primary

keys of those tables.Exhibit 5-16: Swampland Real Estate Step-by-Step Design

Page 27: 1 Database Design and Development: A Visual Approach © 2006 Prentice Hall Chapter 5 DATABASE DESIGN AND DEVELOPMENT: A VISUAL APPROACH Chapter 5 Advanced

Database Design and Development: A Visual Approach © 2006 Prentice Hall

Chapter 5

27

Complex Design:Swampland Real Estate

Exhibit 5-17: Swampland Real Estate ER Diagram

Data Types

Page 28: 1 Database Design and Development: A Visual Approach © 2006 Prentice Hall Chapter 5 DATABASE DESIGN AND DEVELOPMENT: A VISUAL APPROACH Chapter 5 Advanced

Database Design and Development: A Visual Approach © 2006 Prentice Hall

Chapter 5

28

Practice Exercise 6:Event Planning Sheet

Exhibit 5-18: The Event Planning Sheet

Page 29: 1 Database Design and Development: A Visual Approach © 2006 Prentice Hall Chapter 5 DATABASE DESIGN AND DEVELOPMENT: A VISUAL APPROACH Chapter 5 Advanced

Database Design and Development: A Visual Approach © 2006 Prentice Hall

Chapter 5

29Exhibit 5-19: A Recipe Card

Practice Exercise 6:Recipe Card

Page 30: 1 Database Design and Development: A Visual Approach © 2006 Prentice Hall Chapter 5 DATABASE DESIGN AND DEVELOPMENT: A VISUAL APPROACH Chapter 5 Advanced

Database Design and Development: A Visual Approach © 2006 Prentice Hall

Chapter 5

30

Practice Exercise 6:Second Recipe Card

Exhibit 5-20: A Second Recipe Card