You are on page 1of 1

Chapter 1: Creating 43

product_number INTEGER NOT NULL REFERENCES product_catalog,


requested_quantity INTEGER NOT NULL,
estimated_shipping_date DATE NOT NULL,
PRIMARY KEY ( order_number, product_number ) );
Redundancy is eliminated because the product_description for each different
product is stored exactly once. Plus, there is now a place to store product infor-
mation before the first order is received and after the last order has been deleted.

1.16.3 Third Normal Form


Third Normal Form (3NF) eliminates any non-key column that does not depend
on the primary key. In the order table the salesperson_phone column depends on
salesperson_name, which is not part of the primary key. This violates Third
Normal Form.
The problems are the same as with Second Normal Form. First, there is
redundancy: If a salespersons phone number changes, it must be changed in
every order row containing that value. Second, there is no place to store infor-
mation about a new salesperson until that person gets an order.
The solution is to move the salesperson columns up into a new table, sales-
person, with the new salesperson_id column as the primary key. The order table
becomes sales_order, with a salesperson_id column added as a foreign key
pointing to the new salesperson table.
CREATE TABLE salesperson (
salesperson_id INTEGER NOT NULL PRIMARY KEY,
name VARCHAR ( 100 ) NOT NULL,
phone VARCHAR ( 100 ) NOT NULL );

CREATE TABLE sales_order (


order_number INTEGER NOT NULL PRIMARY KEY,
client_name VARCHAR ( 100 ) NOT NULL,
shipping_address VARCHAR ( 1000 ) NOT NULL,
salesperson_id INTEGER NOT NULL REFERENCES salesperson,
salesperson_commission NUMERIC ( 6, 3 ) NOT NULL );

CREATE TABLE product_catalog (


product_number INTEGER NOT NULL PRIMARY KEY,
product_description VARCHAR ( 100 ) NOT NULL );

CREATE TABLE product_order (


order_number INTEGER NOT NULL REFERENCES sales_order,
product_number INTEGER NOT NULL REFERENCES product_catalog,
requested_quantity INTEGER NOT NULL,
estimated_shipping_date DATE NOT NULL,
PRIMARY KEY ( order_number, product_number ) );
Redundancy is eliminated because information about each salesperson is stored
exactly once. Also, there is now a place to store salesperson information before
the first order is received and after the last order has been deleted.
Normalization depends on the business rules governing the data. It is not
always possible to normalize a design by simply looking at the schema. For
example, if each salesperson receives a fixed commission for all sales, the sales-
person_commission column should also be moved to the salesperson table. In
this example, however, salesperson_commission remains in the sales_order
table because the commission can change from order to order.

You might also like