Lab 8 - Seneca

advertisement
DBS201 Lab 8
Normalization
Purpose:
 Convert a user view to a table view
 Start Normalization – do first normal form (1NF)
 Eliminate the repeating groups
 Identify a primary key for the user view
 Create the dependency diagram for 1NF (show functional dependencies)
Definition: Normalization is the process of assigning attributes to relations in such a way that
data redundancies are reduced or eliminated.
Definition: User Views can be individual descriptions, reports, forms, or lists of data that are
required to support the operations of a particular database user.
Part A: Converting a user view to a table view
The purpose of this step is to get the user view ready to be analyzed as a relational structure.
There is not necessarily any physical change to what you are looking at. Through this
process, you are gaining an understanding of the data that is in the view and what it
represents.
Here is an example of a user view. This report lists the customers of the Premiere
Corporation.
Cust
No
124
256
311
315
405
412
522
Name
Sally
Ann
Don
Tom
Al
Sally
Mary
Premiere Corporation Customer List
Street
City
State
Adams
Samuels
Charles
Daniels
Williams
Adams
Nelson
482 Oak
215 Pete
48 College
914 Cherry
519 Watson
16 Elm
108 Pine
Lansing
Grant
Ira
Kent
Grant
Lansing
Ada
MI
MI
MI
MI
MI
MI
MI
Zip
Code
49224
49219
49034
48391
49219
49224
49441
Sales
Rep #
03
06
12
06
12
03
12
A. Examine the user view: As you examine this report, you can see that it contains a
title, a line of column headings and the body of the report. Each line in the body of the
report contains data about a particular customer. For example we can see that in the
first line of the body of the report, there is data about Customer 124. This customer’s
name is Sally Adams and she lives at 482 Oak in Lansing,Michigan (MI). The Sales
Representative who calls on Sally Adams is Sales Rep Number 03.
B. Identify all attributes: The attributes (or characteristics) of a User View can often be
found by simply looking at the column headings. In our Customer Report we see that
DBS201 Lab 8
Normalization
we have the following attributes: Customer Number, Customer Name, Street, City,
State, Zip Code and Sales Representative Number.
C. Visualize the user view as a table: In this case, the user view looks very similar to a
table. It has column headings which can relate to column headings in a table. Each
line of the report will become a row in the table.
Now you try it. Examine the following report:
Part
Number
AX12
AZ52
BA74
BH22
BT04
BZ66
CA14
CB03
CX11
CZ81
Premiere Corporation Parts List
Part
Qty
Class Warehouse
Description
On Hand
Iron
Dartboard
Basketball
Cornpopper
GasGrill
Washer
Griddle
Bike
Blender
Treadmill
104
20
40
95
11
52
78
44
112
68
HW
SG
SG
HW
AP
AP
HW
SG
HW
SG
3
2
1
3
2
3
3
1
3
2
Price
24.95
12.95
29.95
24.95
149.99
399.99
39.99
299.99
22.95
349.95
What type of data does each line in the report represent?
_________________________________________________________________
What attributes can you identify from the user view?
________________________________
________________________________
________________________________
________________________________
________________________________
________________________________
Part B: Start 1NF.
Step 1: Eliminate Repeating Groups:
First normal form is basically a three step process. You need to eliminate repeating groups,
identify a primary key for each row and define the functional dependencies.
Definition: A repeating group is an attribute or collection of attributes within a relation that
has multiple values for a single occurrence of the primary key for that relation.
Definition: Functional dependency is where all attributes in the table are dependent on the
primary key for that relation.
DBS201 Lab 8
Normalization
For example, looking at the following User View, we see that for each Customer number, it is
possible to have multiple values for the order number and order date attributes. Therefore
the order number and date are a repeating group. To get rid of the repeating group however,
it is necessary to populate every cell of this table view (previously referred to as a user view).
Premiere Corporation Customer Orders
Customer
Name
Order
Order
Number
Number
Date
124
Sally
Adams
256
311
315
522
Ann
Don
Tom
Mary
Samuels
Charles
Daniels
Nelson
12489
12500
12495
12491
12494
12498
12504
2001-09-02
2001-09-05
2001-09-04
2001-09-02
2001-09-04
2001-09-05
2001-09-05
The table with repeating groups eliminated:
Premiere Corporation Customer Orders
Customer
Name
Order
Order
Number
Number
Date
124
124
256
311
315
522
522
Sally
Sally
Ann
Don
Tom
Mary
Mary
Adams
Adams
Samuels
Charles
Daniels
Nelson
Nelson
12489
12500
12495
12491
12494
12498
12504
2001-09-02
2001-09-05
2001-09-04
2001-09-02
2001-09-04
2001-09-05
2001-09-05
Note that every ‘cell’ now has data in it.
Step 2: Identify a primary key for the table:
Now identify the attribute or attributes that can uniquely identify this relation. This is the
hardest step to do when doing 1NF. It is important to understand what the data represents.
Premiere Corporation Customer Orders
Customer
Name
Order
Order
Number
Number
Date
124
124
256
311
315
522
522
Sally
Sally
Ann
Don
Tom
Mary
Mary
Adams
Adams
Samuels
Charles
Daniels
Nelson
Nelson
12489
12500
12495
12491
12494
12498
12504
2001-09-02
2001-09-05
2001-09-04
2001-09-02
2001-09-04
2001-09-05
2001-09-05
DBS201 Lab 8
Normalization
In this table of data, the most obvious candidates would be something that can uniquely
identify data. In this case customer number and order number are the most obvious
candidates. However, which one? If you chose customer number, it could uniquely identify
name but not order number or order data. If you chose order number, it could identify order
data, but not name. If you chose customer number and order number, in combination you
can identify name and order date.
Step 3: Define the functional dependencies:
The best technique to show functional dependencies is to draw a dependency diagram. A
dependency diagrams shows the relationship of the attributes to the primary key. We have
already said that the combination of customer number and order number is the primary key.
The dependency diagram for 1NF will look like this:
Customer number
Name
Order number
Order date
Knowing this functional dependency, we can now state a table definition for this.
a.
b.
Choose an appropriate name for the relation. We chose to name our relation
Customer Order because each line in the report describes customer data and
order data.
List the attributes you found in the user view inside square brackets, giving each
attribute a suitable attribute name. Note: calculated fields or derived fields
should not be included. Underline primary keys or place (PK) next to the
attributes that represent the primary key.
The definition for this relation resulting from our Customer Orders data view would look as
follows:
Customer_Order [ CustNo, OrderNo, CustName, OrderDate ]
DBS201 Lab 8
Normalization
TO BE HANDED IN (BY THE END OF THIS LAB PERIOD):
Name __________________________ Student No.______________________
For the following User View, determine the 1NF and hand in this page to your
instructor.
Premiere Corporation Order Detail Report
Order
Number
Order
Date
Cust
Part
Part
Number Number Desc
12489
12491
2001-09-02
2001-09-02
124
311
12494
12495
12498
2001-09-04
2001-09-04
2001-09-05
315
256
522
12500
12504
2001-09-05
2001-09-05
124
522
AX12
BT04
BZ66
CB03
CX11
AZ52
BA74
BT04
CZ81
Number Quoted
Ordered Price
Iron
GasGrill
Washer
Bike
Blender
Dartboard
Basketball
GasGrill
Treadmill
11
1
1
4
2
2
4
1
2
14.95
149.99
399.99
279.99
22.95
12.95
24.95
149.99
325.99
Total
164.45
149.99
399.99
1,119.96
45.90
25.90
99.80
149.99
651.98
State the table definition after the dependency diagram by giving the table a meaningful name
and denoting primary key(s) by either underlining the attribute(s) or putting a (pk) next to the
attribute(s).
What is the primary key for this data relation?
Dependency Diagram:
OrderNo
OrderDate
CustNo
PartNo
PartDesc
NumOrdered
QuotedPrice
Download