Chapter 5 DATABASE DESIGN AND DEVELOPMENT A VISUAL

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

Chapter 5 Recursive Relationships Original Design of the Enrollment Database Exhibit 5 -1: Enrollment Database Design and Development: A Visual Approach © 2006 Prentice Hall 2

Chapter 5 Mentor Recursive Relationships Instructor 11 mentors instructors 22 and 33. Instructor 33 mentors instructor 44. Database Design and Development: A Visual Approach © 2006 Prentice Hall Exhibit 5 -2: Mentor Relationships for Enrollment Database 3

Chapter 5 Implementing a Recursive Relationship A foreign key (INSTRUCTOR$id) is added to the INSTRUCTOR table, which is a copy of the primary key of that same table. Database Design and Development: A Visual Approach © 2006 Prentice Hall Exhibit 5 -3: Data Relationships for Mentor Recursive Relationship 4

Chapter 5 ER Diagram with a Recursive Relationship With the foreign key added, there is now a one -to-many relationship between instructors. Database Design and Development: A Visual Approach © 2006 Prentice Hall Exhibit 5 -4: Enrollment Database Diagram with Recursive Relationship 5

Chapter 5 Bill-of-Materials 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 subproducts, and a product can be a sub-product in many larger products. Exhibit 5 -5: Bill-of-Materials Example Database Design and Development: A Visual Approach © 2006 Prentice Hall 6

Chapter 5 Bill-of-Materials in Table Form 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. Exhibit 5 -6: Bill of Materials Table Database Design and Development: A Visual Approach © 2006 Prentice Hall 7

Chapter 5 ER Diagram for a Many-to-Many Recursive Relationship 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. Exhibit 5 -7: Bill-of Materials ER Diagram Database Design and Development: A Visual Approach © 2006 Prentice Hall 8

Chapter 5 Many-to-Many Recursive Relationship Data Exhibit 5 -8: Bill-of-Materials Database Tables Database Design and Development: A Visual Approach © 2006 Prentice Hall 9

Chapter 5 Supertype/Subtype Hierarchies The first four columns apply to all equipment but the last four apply to only some equipment, which results in empty cells. Exhibit 5 -9: Equipment Entity and Database Design and Development: A Visual Approach © 2006 Prentice Hall 10

Chapter 5 Equipment Supertype/Subtype Hierarchy 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. Database Design and Development: A Visual Approach © 2006 Prentice Hall Exhibit 5 -10: Equipment Supertype/Subtype Hierarchy 11

Chapter 5 Supertype/Subtype Example All three tables share four common fields. Database Design and Development: A Visual Approach © 2006 Prentice Hall Exhibit 5 -11: STUDENT, FACULTY and STAFF tables 12

Chapter 5 Person Supertype/Subtype Hierarchy Step 1: Tables - Start by identifying three different tables. Step 2: Fields and Keys - Add the fields and designate the primary keys. Step 3: Recognize Common Fields - Make sure that the fields actually store the same data for each entity. Database Design and Development: A Visual Approach © 2006 Prentice Hall Exhibit 5 -12: Person Supertype/Subtype Hierarchy 13

Chapter 5 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. Database Design and Development: A Visual Approach © 2006 Prentice Hall Exhibit 5 -12: Person Supertype/Subtype Hierarchy 14

Chapter 5 More Complex Supertype/Subtype Example 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. Exhibit 5 -13: Athlete/SGA Hierarchy Database Design and Development: A Visual Approach © 2006 Prentice Hall 15

Chapter 5 Complex Design Example: Summer Reading Fun Step 1: Tables - The problem statement refers to five entities: students, books, skills, fiction books and nonfiction books. Database Design and Development: A Visual Approach © 2006 Prentice Hall Exhibit 5 -14: Summer Reading Fun Step-by-Step Design 16

Chapter 5 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. Database Design and Development: A Visual Approach © 2006 Prentice Hall Exhibit 5 -14: Summer Reading Fun Step-by-Step Design 17

Chapter 5 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. Database Design and Development: A Visual Approach © 2006 Prentice Hall Exhibit 5 -14: Summer Reading Fun Step-by-Step Design 18

Chapter 5 Complex Design Example: Summer Reading Fun Step 4: Fields - The fields identified in the problem statement are added to the tables. Database Design and Development: A Visual Approach © 2006 Prentice Hall Exhibit 5 -14: Summer Reading Fun Step-by-Step Design 19

Chapter 5 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. Database Design and Development: A Visual Approach © 2006 Prentice Hall Exhibit 5 -14: Summer Reading Fun Step-by-Step Design 20

Chapter 5 Complex Design Example: Summer Reading Fun Data Types Database Design and Development: A Visual Approach © 2006 Prentice Hall Exhibit 5 -15: Summer Reading Fun ER Diagram 21 With Data Types

Chapter 5 Complex Design: Swampland Real Estate Step 1: Tables - The problem statement refers to seven entities: property, agency, area, outlet, client and the single-family and condo property types. Database Design and Development: A Visual Approach © 2006 Prentice Hall Exhibit 5 -16: Swampland Real Estate Step-by-Step Design 22

Chapter 5 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. Database Design and Development: A Visual Approach © 2006 Prentice Hall Exhibit 5 -16: Swampland Real Estate Step-by-Step Design 23

Chapter 5 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. Database Design and Development: A Visual Approach © 2006 Prentice Hall Exhibit 5 -16: Swampland Real Estate Step-by-Step Design 24

Chapter 5 Complex Design: Swampland Real Estate Step 4: Fields - The fields identified in the problem statement are added to the tables. Database Design and Development: A Visual Approach © 2006 Prentice Hall Exhibit 5 -16: Swampland Real Estate Step-by-Step Design 25

Chapter 5 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. Database Design and Development: A Visual Approach © 2006 Prentice Hall Exhibit 5 -16: Swampland Real Estate Step-by-Step Design 26

Chapter 5 Complex Design: Swampland Real Estate Data Types Database Design and Development: A Visual Approach © 2006 Prentice Hall Exhibit 5 -17: Swampland Real Estate ER Diagram 27

Chapter 5 Practice Exercise 6: Event Planning Sheet Exhibit 5 -18: The Event Planning Sheet Database Design and Development: A Visual Approach © 2006 Prentice Hall 28

Chapter 5 Practice Exercise 6: Recipe Card Exhibit 5 -19: A Recipe Card Database Design and Development: A Visual Approach © 2006 Prentice Hall 29

Chapter 5 Practice Exercise 6: Second Recipe Card Exhibit 5 -20: A Second Recipe Card Database Design and Development: A Visual Approach © 2006 Prentice Hall 30
- Slides: 30