Database System Chapter 2 Database Design 2 - Design Method
Database System Chapter 2 Database Design 2 - Design Method
Database System Chapter 2 Database Design 2 - Design Method
Chapter 6
Database Design 2: Design Method
Objectives
fb.me/SophornDS 1
Objectives (continued)
Objectives (continued)
fb.me/SophornDS 2
Introduction
User Views
fb.me/SophornDS 3
Information-Level Design Method
fb.me/SophornDS 4
• For example, suppose a requested user view
involves departments and employees, each
department can hire many employees, and
each employee can work in only one
department (a typical restriction).
10
fb.me/SophornDS 5
Normalize the Tables
11
12
fb.me/SophornDS 6
Identify All Keys (continued)
13
14
fb.me/SophornDS 7
Database Design Language (DBDL)
15
16
fb.me/SophornDS 8
Entity-Relationship (E-R) Diagrams
17
18
fb.me/SophornDS 9
Entity-Relationship (E-R) Diagrams
(continued)
19
20
fb.me/SophornDS 10
Merge the Result into the Design
21
fb.me/SophornDS 11
Database Design Examples
23
24
fb.me/SophornDS 12
Database Design Examples (Cont.)
25
26
fb.me/SophornDS 13
Database Design Examples (Cont.)
• Or a single table:
Customer (CustomerNum, CustomerName,
Street, City, State, Zip, Balance,
CreditLimit, RepNum, LastName, FirstName)
• The table is in 2NF but it’s not in 3NF
27
28
fb.me/SophornDS 14
Database Design Examples (Cont.)
29
30
fb.me/SophornDS 15
Database Design Examples (Cont.)
31
32
fb.me/SophornDS 16
Database Design Examples (Cont.)
34
fb.me/SophornDS 17
Database Design Examples (Cont.)
35
36
fb.me/SophornDS 18
Database Design Examples
(continued)
• Henry Books database: information about
branches, publishers, authors, and books
• User view requirements
FIGURE 6-9: DBDL for Book database after first user view
37
FIGURE 6-10: DBDL for Book database after second user view
38
fb.me/SophornDS 19
Database Design Examples
(continued)
Physical-Level Design
• Undertaken after information-level design completion
• Most DBMSs support primary, candidate, secondary,
and foreign keys
• To enforce restrictions, DB programmers must
include logic in their programs
Employee (EmployeeNum,LastName,FirstName,
Street,City,State,Zip,WageRate,SocSecNum,
DepartmentNum)
AK SocSecNum
SK LastName
FK DepartmentNum Department
40
fb.me/SophornDS 20
Top-Down Versus Bottom-Up
41
Survey Form
42
fb.me/SophornDS 21
Obtaining Information from Existing
Documents
• Existing documents can furnish information
about database design
• Identify and list all columns and give them
appropriate names
• Identify functional dependencies
• Determine the tables and assign columns
43
44
fb.me/SophornDS 22
Obtaining Information from Existing
Documents (continued)
46
fb.me/SophornDS 23
Obtaining Information from Existing
Documents (continued)
47
48
fb.me/SophornDS 24
Obtaining Information from Existing
Documents (continued)
• Customer (CustomerNumber, CustomerSoldToName,
CustomerSoldToAddressLine1,
CustomerSoldToAddressLine2, CustomerSoldToCity,
CustomerSoldToState,
CustomerSoldToZip,CustomerRepNumber,
CustomerRepLastName, CustomerRepFirstName)
• Part (ItemNumber, ItemDescription, ItemPrice)
• Invoice (InvoiceNumber, InvoiceDate, OrderNumber,
ShipDate, Freight, InvoiceTotal)
• Order (OrderNumber, OrderDate, CustomerPONumber,
CustomerShipToName, CustomerShipToAddressLine1,
CustomerShipToAddressLine2, CustomerShipToCity,
CustomerShipToState, CustomerShipToZip)
• OrderLine (OrderNumber, ItemNumber,
ItemQuantityOrdered, ItemQuantityShipped,
ItemQuantityBackordered, ItemPrice) 49
One-to-One Relationship
Considerations
• Simply including the primary key of each table as a
foreign key in the other table
– No guarantee that the information will match
• One solution: create a single table
– Workable, but not the best solution
• Better solution
– Create separate tables for customers and sales reps
– Include the primary key of one of them as a foreign
key in the other
50
fb.me/SophornDS 25
One-to-One Relationship
Considerations (continued)
51
One-to-One Relationship
Considerations (continued)
52
fb.me/SophornDS 26
One-to-One Relationship
Considerations (continued)
53
One-to-One Relationship
Considerations (continued)
fb.me/SophornDS 27
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
• Deciding between a single many-to-many-to-many
relationship and two (or three) many-to-many
relationships
– Crucial issue: independence
55
Many-to-Many Relationship
Considerations (continued)
56
fb.me/SophornDS 28
Many-to-Many Relationship
Considerations (continued)
FIGURE 6-25: Result obtained by splitting the Sales table into three tables
57
Many-to-Many Relationship
Considerations (continued)
FIGURE 6-26: Result obtained by joining three tables—the second and third
rows are in error!
58
fb.me/SophornDS 29
Nulls and Entity Subtypes
• Null
– Special value
– Represents absence of a value in a field
– Used when a value is unknown or inapplicable
• Splitting tables to avoid use of null values
• Entity subtype: table that is a subtype of another
table
59
fb.me/SophornDS 30
Nulls and Entity Subtypes (continued)
61
62
fb.me/SophornDS 31
Nulls and Entity Subtypes (continued)
63
64
fb.me/SophornDS 32
Nulls and Entity Subtypes (continued)
65
66
fb.me/SophornDS 33
The Entity-Relationship Model
68
fb.me/SophornDS 34
The Entity-Relationship Model
(continued)
69
70
fb.me/SophornDS 35
The Entity-Relationship Model
(continued)
71
72
fb.me/SophornDS 36
The Entity-Relationship Model
(continued)
73
FIGURE 6-40: Complete E-R diagram for the Premiere Products database
74
fb.me/SophornDS 37
The Entity-Relationship Model
(continued)
FIGURE 6-41: E-R diagram with an existence dependency and a weak entity
75
76
fb.me/SophornDS 38
The Entity-Relationship Model
(continued)
77
Summary
• Database design is a two-part process:
information-level design (not dependent on a
particular DBMS), and physical-level design
(appropriate for the particular DBMS being used)
• User view: set of necessary requirements to
support a particular user’s operations
• Information-level design steps for each user view:
represent the user view as a collection of tables,
normalize these tables, represent all keys (primary,
alternate, secondary, and foreign), and merge the
results into the cumulative design
78
fb.me/SophornDS 39
Summary (continued)
79
Summary (continued)
80
fb.me/SophornDS 40
Summary (continued)
• If a table’s primary key consists of three (or more)
columns, determine whether there are independent
relationships between pairs of these columns
• If a table contains columns that can be null and the
nulls mean that the column is inapplicable for some
rows, you can split the table, placing the null
column(s) in separate tables
• The result of merging third normal form tables may
not be in third normal form
• Entity-relationship (E-R) model represents the
structure of a database using an E-R diagram
81
fb.me/SophornDS 41