Module 5 Lecture
Module 5 Lecture
Ninth Edition
Chapter 5
Database Design
Copyright © 2020, 2017, 2015 Pearson Education, Inc. All Rights Reserved
Learning Objectives
2
Copyright © 2020, 2017, 2015 Pearson Education, Inc. All Rights Reserved
The Purpose of a Database Design
3
Copyright © 2020, 2017, 2015 Pearson Education, Inc. All Rights Reserved
Figure 5.1 The Steps for Transforming
4
Copyright © 2020, 2017, 2015 Pearson Education, Inc. All Rights Reserved
Figure 5.2 The ITEM Entity and Table
5
Copyright © 2020, 2017, 2015 Pearson Education, Inc. All Rights Reserved
Figure 5.3 The Final ITEM Table
6
Copyright © 2020, 2017, 2015 Pearson Education, Inc. All Rights Reserved
Figure 5.4 The CUSTOMER Entity
7
and Table
Copyright © 2020, 2017, 2015 Pearson Education, Inc. All Rights Reserved
Denormalization
9
Copyright © 2020, 2017, 2015 Pearson Education, Inc. All Rights Reserved
10
Copyright © 2020, 2017, 2015 Pearson Education, Inc. All Rights Reserved
Represent Weak Entities
11
Copyright © 2020, 2017, 2015 Pearson Education, Inc. All Rights Reserved
Figure 5.7 The SALES_COMMISSION
12
Copyright © 2020, 2017, 2015 Pearson Education, Inc. All Rights Reserved
A Relational Design for the
13
SALES_COMMISSION Entity (1 of 2)
Understand the need for normalization
• Consider the original attributes of the SALES_COMMISSION entity on
the previous slide
Copyright © 2020, 2017, 2015 Pearson Education, Inc. All Rights Reserved
A Relational Design for the
14
SALES_COMMISSION Entity (2 of 2)
Understand the need for normalization
• One look at the previous functional dependencies reveals that the
original table, given the primary key CheckNumber, should actually be
called COMMISSION_CHECK.
• Once normalized properly you have…
Copyright © 2020, 2017, 2015 Pearson Education, Inc. All Rights Reserved
Figure 5.8 The Normalized SALES_
15
Copyright © 2020, 2017, 2015 Pearson Education, Inc. All Rights Reserved
Representing 1:1 Relationships
16
Copyright © 2020, 2017, 2015 Pearson Education, Inc. All Rights Reserved
Figure 5.10 1:1 Strong Entity
17
Relationships
Copyright © 2020, 2017, 2015 Pearson Education, Inc. All Rights Reserved
Results of a 1:1 Relationship
18
Copyright © 2020, 2017, 2015 Pearson Education, Inc. All Rights Reserved
Figure 5.11 1:1 Strong Entity
19
Copyright © 2020, 2017, 2015 Pearson Education, Inc. All Rights Reserved
Representing 1:N Strong Entity
20
Relationships
Know how to represent 1:1, 1:N, and N:M binary
relationships
• Like a 1:1 relationship, a 1:N relationship is saved by placing
the key from one table into another as a foreign key.
• However, in a 1:N the foreign key always goes into the many-
side of the relationship:
– the 1 side is called the parent
– the N side is called the child
Copyright © 2020, 2017, 2015 Pearson Education, Inc. All Rights Reserved
Figure 5.12 1:N Strong Entity
21
Relationships
Copyright © 2020, 2017, 2015 Pearson Education, Inc. All Rights Reserved
Results of a 1:N Relationship
22
Copyright © 2020, 2017, 2015 Pearson Education, Inc. All Rights Reserved
Representing N:M Strong Entity
23
Relationships
Know how to represent 1:1, 1:N, and N:M binary
relationships
• To create an N:M relationship, a new table is created. This
table is called an intersection table.
• An intersection table has a composite key consisting of the
keys from each of the tables that it connects.
Copyright © 2020, 2017, 2015 Pearson Education, Inc. All Rights Reserved
Figure 5.13 N:M Strong Entity
24
Relationships
Copyright © 2020, 2017, 2015 Pearson Education, Inc. All Rights Reserved
Figure 5.14 Incorrect Representation
25
of an N:M Relationship
Copyright © 2020, 2017, 2015 Pearson Education, Inc. All Rights Reserved
Figure 5.15 Representing a N:M
26
Copyright © 2020, 2017, 2015 Pearson Education, Inc. All Rights Reserved
Results of a N:M Relationships
27
Copyright © 2020, 2017, 2015 Pearson Education, Inc. All Rights Reserved
Figure 5.18 The Association
28
Relationship
Copyright © 2020, 2017, 2015 Pearson Education, Inc. All Rights Reserved
Figure 5.19 Mixed Entity Relationship
29
Example
Copyright © 2020, 2017, 2015 Pearson Education, Inc. All Rights Reserved
Figure 5.20 Representing Subtypes
30
Copyright © 2020, 2017, 2015 Pearson Education, Inc. All Rights Reserved
Representing Recursive
31
Relationships
Know how to represent 1:1, 1:N, and N:M
recursive relationships
• A recursive relationship is a relationship among entities of the
same class (a relationship with itself).
• There are three types of recursive relationships:
– 1:1 and 1:M relationships are saved using foreign keys
– M:M relationships are saved by creating an intersecting
relation
Copyright © 2020, 2017, 2015 Pearson Education, Inc. All Rights Reserved
Figure 5.21 Example Recursive
32
Relationships
Copyright © 2020, 2017, 2015 Pearson Education, Inc. All Rights Reserved
Figure 5.22 Example 1:1 Recursive
33
Relationship
Copyright © 2020, 2017, 2015 Pearson Education, Inc. All Rights Reserved
Figure 5.23 Example 1:N Recursive
34
Relationship
Copyright © 2020, 2017, 2015 Pearson Education, Inc. All Rights Reserved
Figure 5.24 Example N:M Recursive
35
Relationship
Copyright © 2020, 2017, 2015 Pearson Education, Inc. All Rights Reserved
Figure 5.25 The Final Data Model for
36
Copyright © 2020, 2017, 2015 Pearson Education, Inc. All Rights Reserved
Specifying Column Properties
37
Copyright © 2020, 2017, 2015 Pearson Education, Inc. All Rights Reserved
38
Column Name Data Type (Length) Key Required Default Value Remarks
CustomerID Integer Primary Yes DBMS Supplied
Key Surrogate Key:
Initial Value=1
Increment=1
LastName Char (25) No Yes None Blank
FirstName Char (25) No Yes None Blank
EmailAddress VarChar (100) Primary Key Yes None Blank
EncryptedPassword VarChar(50) No No None Blank
Phone Char (12) No Yes None Format: ###-###-####
Copyright © 2020, 2017, 2015 Pearson Education, Inc. All Rights Reserved
39
Column Name Data Type (Length) Key Required Default Value Remarks
InvoiceNumber Integer Primary Key Yes DBMS supplied Surrogate Key:
Initial
value=35000
Increment=1
InvoiceDate Date No Yes None Format: yyyy-
mm-dd
PaymentType Char (25) No Yes Cash Blank
Subtotal Numeric (9,2) No No None Blank
Shipping Numeric (9,2) No No None Blank
Tax Numeric (9,2) No No None Blank
Total Numeric (9,2) No No None Blank
Copyright © 2020, 2017, 2015 Pearson Education, Inc. All Rights Reserved
40
Column Name Data Type (Length) Key Required Default Value Remarks
ProductNumber Char (35) Primary Key Yes None Blank
ProductType Char (24) No Yes None Blank
ProductDescription VarChar (100) No Yes None Blank
UnitPrice Numeric (9, 2) No Yes None Blank
QuantityOnHand Integer No Yes 0 Blank
Copyright © 2020, 2017, 2015 Pearson Education, Inc. All Rights Reserved
41
Copyright © 2020, 2017, 2015 Pearson Education, Inc. All Rights Reserved
Heather Sweeney’s Database Design
42
Schema
Learn how to transform E-R data models into
relational designs
Copyright © 2020, 2017, 2015 Pearson Education, Inc. All Rights Reserved
43
Copyright © 2020, 2017, 2015 Pearson Education, Inc. All Rights Reserved
Copyright
44
Copyright © 2020, 2017, 2015 Pearson Education, Inc. All Rights Reserved