concepts of database management, fifth edition chapter 6: database design 2: design methodology
TRANSCRIPT
Concepts of Database Concepts of Database Management, Fifth Management, Fifth
EditionEdition
Chapter 6: Chapter 6: Database Design 2:Database Design 2:Design MethodologyDesign Methodology
2Concepts of Database Management, 5th Edition
Objectives Discuss the general process and goals of
database design
Define user views and explain their function
Define database design language and use it to document database designs
Create an entity-relationship diagram to visually represent a database design
Present a methodology for database design at the information level and view examples illustrating this methodology
3Concepts of Database Management, 5th Edition
Objectives
Explain the physical-level design process
Discuss top-down and bottom-up approaches to database design and examine the advantages and disadvantages of both methods
Use a survey form to obtain information from users prior to beginning the database design process
Review existing documents to obtain information prior to beginning the database design
4Concepts of Database Management, 5th Edition
Objectives Discuss special issues related to implementing
one-to-one relationships and many-to-many relationships involving more than two entities
Discuss entity subtypes and their relationships to nulls
Learn how to avoid potential problems when merging third normal form relations
Examine the entity-relationship model for representing and designing databases
5Concepts of Database Management, 5th Edition
Database Design Information-level Design – building a database that
satisfies the organization’s requirements as cleanly as possible
Physical-level design – designers transform the information-level design into a design for the specific DBMS used by the organization
User Views – requirements necessary to support a particular user’s operations
Cumulative design – supports all user views encountered so far in the design process
6Concepts of Database Management, 5th Edition
Information-Level Design Methodology
Information-level Design Methodology
Represent user view as collection of tables
Normalize these tables
Identify all keys
Merge the result into design
7Concepts of Database Management, 5th Edition
Represent User View as Collection of Tables
Step 1: Determine entities involved and create separate table for each type
Step 2: Determine primary key for each table
Step 3: Determine properties for each entities
Step 4: Determine relationships among entities
8Concepts of Database Management, 5th Edition
Types of Relationships
One-to-Many Relationships – created by including the primary key of the “one” table as a foreign key in the “many” table
Many-to-Many Relationships – created with a new table whose primary key is the combination of the primary keys of the original tables
One-to-One Relationship – created with a single relationship from one record in a table to a single record in another table
9Concepts of Database Management, 5th Edition
Normalize the Tables
Represent all keys
Primary, alternate, secondary, foreign
Database Design Language (DBDL)
Mechanism for representing tables and keys
DBDL Example
Figure 6.1
10Concepts of Database Management, 5th Edition
Types of Primary Keys Three types of primary keys used in database
design
1. Natural key (logical key or intelligent key) – consists of a column that uniquely identifies an entity
2. Artificial key – column created for an entity to serve solely as the primary key; visible to users
3. Surrogate key (synthetic key) – system-generated primary key usually hidden from users
11Concepts of Database Management, 5th Edition
DBDL Notation
Table name followed by columns in parentheses
Primary key column(s) underlined
AK identifies alternate keys
SK identifies secondary keys
FK identifies foreign keys
12Concepts of Database Management, 5th Edition
Entity-Relationship Diagrams
Diagram that visually represents database structure
Rectangle represents each entity in the E-R diagram
Primary key for each entity appears above the line in the rectangle for each entry
13Concepts of Database Management, 5th Edition
Entity-Relationship Diagrams
Other columns that comprise each entity appear below the line within each rectangle
The letters AK, SK, and FK appear in parentheses following the alternate key, secondary key, and foreign key respectively
For each foreign key, there is a line leading from the rectangle that corresponds to the table being identified to the rectangle that corresponds to the table containing the foreign key
14Concepts of Database Management, 5th Edition
Figure 6.2: Entity-Relationship Diagrams
15Concepts of Database Management, 5th Edition
Merge the Result into the Design
As soon as Steps 1 through 3 for a given user view have been completed, the results can be merged into the cumulative design
If the working view is the first user view, the cumulative design will be identical to the design for the first user
Otherwise, all the tables for this user with those that are currently in the cumulative design
16Concepts of Database Management, 5th Edition
Merge the Result into the Design (con’t)
Next, you combine tables that have the same primary key to form a new table
New table has the same primary key as those tables you have combined
New table also contains all the columns from both tables
In the case of duplicate columns, you remove all but one copy of the column
17Concepts of Database Management, 5th Edition
Figure 6.4:User View Examples
View #1: Sales Rep View
Rep (RepNum, LastName, FirstName, Street, City, State, Zip, Commission, Rate)
18Concepts of Database Management, 5th Edition
View #2: Customer View
Figure 6.5:User View Examples
19Concepts of Database Management, 5th Edition
Entities
Independent entity - an entity that does not require a relationship to another entity for identification
Dependent entity - an entity that does require a relationship to another entity for identification
20Concepts of Database Management, 5th Edition
Physical-Level Design
Undertaken after information-level design completion
Most DBMSs support primary, candidate, secondary, and foreign keys
DB programmers must include logic to ensure the uniqueness of primary keys and enforce other conditions
21Concepts of Database Management, 5th Edition
Top-Down vs. Bottom-Up
Bottom-up
Design starts at low level
Specific user requirements drive design process
Top-down
Begins with general database that models overall enterprise
Refines the model until design is achieved
22Concepts of Database Management, 5th Edition
Survey Form
Used to collect information from users
Must contain particular elements
Entity information
Attribute information
Relationships
Functional dependencies
Processing information
23Concepts of Database Management, 5th Edition
Existing Documents
Aid in collecting user requirements
Collect information similar to that collected with survey forms
Entity information
Attribute information
Relationships
Functional dependencies
Processing information
24Concepts of Database Management, 5th Edition
Figure 6.14: Example Invoice
25Concepts of Database Management, 5th Edition
Figure 6.15: List of Possible Attributes
26Concepts of Database Management, 5th Edition
Figure 6.16:Tentative List of Functional Dependencies
27Concepts of Database Management, 5th Edition
Figure 6.17:Revised List of
Functional Dependencies
28Concepts of Database Management, 5th Edition
Figure 6.18:Tentative List of Entities
29Concepts of Database Management, 5th Edition
Figure 6.19:Expanded List of Entities
30Concepts of Database Management, 5th Edition
One-to-One Relationship Considerations
Implementing a one-to-one relationship by simply including the primary key of each table as a foreign key in the other table
A problem is that there is no guarantee that the information will match
31Concepts of Database Management, 5th Edition
One-to-One Relationship Considerations (con’t)
One possible solution is to create a single table
Although workable, two features are not particularly attractive:
1. Combines columns of two different entities into a single table
2. If possible for one entity to exist without the other
32Concepts of Database Management, 5th Edition
One-to-One Relationship Considerations (con’t)
Better solution
Create two separate tables for customers and sales reps and to include the primary key of one of them as a foreign key in the other
This foreign key would also be designated as an alternate key
33Concepts of Database Management, 5th Edition
Figure 6.20:1:1 Relationship Considerations
Include primary key of each table as foreign key in the other
34Concepts of Database Management, 5th Edition
Figure 6.21:1:1 Relationship Considerations
Implementation when information does not match
35Concepts of Database Management, 5th Edition
Figure 6.22:1:1 Relationship Considerations
Implemented in a single table
36Concepts of Database Management, 5th Edition
Figure 6.23:
1:1 Relationship Considerations
1:1 relationship implemented by including primary key of one table as foreign key (and alternative key) in the other
37Concepts of Database Management, 5th Edition
Many-to-Many Relationship Considerations
Complex issues arise when more than two entities are related in a many-to-many relationship
Many-to-many-to-many relationship – involves multiple entities
Crucial issue in making the determination between a single many-to-many-to-many relationship and two (or three) many-to-many relationships is the independence
38Concepts of Database Management, 5th Edition
Figure 6.24: M:M Relationship Considerations
Sample Sales Data
39Concepts of Database Management, 5th Edition
Figure 6.25:M:M Relationship Considerations
Result obtained by splitting Sales table into three tables
40Concepts of Database Management, 5th Edition
Figure 6.26:M:M Relationship Considerations
Result obtained by joining three tables--2 rows are in error. Must be converted to 4NF
41Concepts of Database Management, 5th Edition
Nulls
Null - a special value
Null - actually represents the absence of a value in a field
Nulls - used when a value is either unknown or inapplicable
42Concepts of Database Management, 5th Edition
Nulls are absence of values
Figure 6.27: Table SplitTo Avoid Nulls
43Concepts of Database Management, 5th Edition
Figure 6.28: Sample DBDL
44Concepts of Database Management, 5th Edition
Entity Subtypes
Entity subtype – table that is a subtype of another table
Incomplete category – records that do not fall into the subtype
Complete categories – all records fall into the categories
45Concepts of Database Management, 5th Edition
Figure 6.29: Entity Subtypes
46Concepts of Database Management, 5th Edition
Figure 6.32:Two Entity Subtypes—Incomplete Categories
47Concepts of Database Management, 5th Edition
Figure 6.33: Two Entity Subtypes—Complete Categories
48Concepts of Database Management, 5th Edition
Avoiding Problems with 3NF When Merging Tables
When combining third normal form tables, the result need not be in third normal form
To avoid the problem of creating a table that is not in third normal form, be cautious when representing user views
If you always attempt to determine whether determinants exist and include them in the tables, the problem is often avoided
49Concepts of Database Management, 5th Edition
Entity-Relationship Model
An approach to representing data in a database
Entities are drawn as rectangles
Relationships are drawn as diamonds with lines connecting the entities involved in relationships
50Concepts of Database Management, 5th Edition
Figure 6.34:One-to-many relationship
51Concepts of Database Management, 5th Edition
Figure 6.35:Many-to-Many Relationship
52Concepts of Database Management, 5th Edition
Figure 6.36:Many-to-Many Relationship
53Concepts of Database Management, 5th Edition
Figure 6.37:One-to-Many Relationship
54Concepts of Database Management, 5th Edition
Figure 6.38: Many-to-Many Relationship with Attributes
55Concepts of Database Management, 5th Edition
Composite Entity
Composite entity - an entity that exists to implement a many-to-many relationship
Essentially both an entity and a relationship
Represented in an E-R diagram by a diamond within a rectangle
56Concepts of Database Management, 5th Edition
Figure 6.39:Composite Entity
57Concepts of Database Management, 5th Edition
Figure 6.40: Complete E-R Diagram
58Concepts of Database Management, 5th Edition
E-R Diagram with an Existence Dependency and Weak Entity
Existence dependency - when the existence of one entity depends on the existence of another related entity
Indicate an existence dependency by placing an “E” in the relationship diamond
Weak entity - an entity that depends on another entity for its own existence
A double rectangle encloses a weak entity
59Concepts of Database Management, 5th Edition
Figure 6.41: E-R Diagram with an Existence Dependency and Weak Entity
60Concepts of Database Management, 5th Edition
Cardinality
Cardinality - the number of items that must be included in a relationship
An entity in a relationship with minimum cardinality of zero plays an optional role in the relationship
An entity with a minimum cardinality of one plays a mandatory role in the relationship
61Concepts of Database Management, 5th Edition
Figure 6.43: E-R Diagram that Represents Cardinality
62Concepts of Database Management, 5th Edition
Summary Database design is a two-part process of
determining an appropriate database structure to satisfy a given set of requirements
A user view is the set of necessary requirements to support a particular user’s operations
A database design is represented in a language called Database Design Language (DBDL)
Designs can be represented pictorially using entity-relationship (E-R) diagrams
63Concepts of Database Management, 5th Edition
Summary
Advantages to both top-down and bottom-up approaches
Survey form is useful for documenting the information gathered for database design process
One-to-One and One-to-Many relationships require attention to primary keys
Entity-relationship (E-R) model is a method of representing the structure of a database using an E-R diagram