Sei sulla pagina 1di 1

Chapter 1: Creating 45

CREATE TABLE salesperson_skill (


salesperson_id INTEGER NOT NULL REFERENCES salesperson,
sales_skill_id INTEGER NULL REFERENCES sales_skill,
PRIMARY KEY ( salesperson_id, sales_skill_id ) );
In practice its hard to tell the difference between Third Normal Form and
Boyce-Codd Normal Form. If you transform a table into Third Normal Form,
the chances are good that it will also be in Boyce-Codd Normal Form because
you removed all the redundancies, regardless of the subtle differences in the
definitions.
In fact, chances are your Third Normal Form database design will also be in
Fourth and Fifth Normal Form. The next two sections discuss the rare situations
where Fourth and Fifth Normal Forms differ from Third.

1.16.5 Fourth Normal Form


Fourth Normal Form (4NF) eliminates multiple independent many-to-many
relationships in the same table. In the following example the salesperson_skill
table represents two many-to-many relationships. First, there is a relationship
where one salesperson may have many sales skills, and conversely, one sales
skill can be shared by multiple salespersons. Second, there is a many-to-many
relationship between salesperson and technical skill. These two relationships are
independent; a salespersons technical and sales skills do not depend on one
another, at least as far as this design is concerned.
CREATE TABLE salesperson (
salesperson_id INTEGER NOT NULL PRIMARY KEY,
salesperson_name VARCHAR ( 100 ) NOT NULL );

CREATE TABLE sales_skill (


sales_skill_id INTEGER NOT NULL PRIMARY KEY,
description LONG VARCHAR );

CREATE TABLE technical_skill (


technical_skill_id INTEGER NOT NULL PRIMARY KEY,
description LONG VARCHAR );

CREATE TABLE salesperson_skill (


salesperson_id INTEGER NOT NULL REFERENCES salesperson,
sales_skill_id INTEGER NOT NULL REFERENCES sales_skill,
technical_skill_id INTEGER NOT NULL REFERENCES technical_skill,
PRIMARY KEY ( salesperson_id, sales_skill_id, technical_skill_id ) );
It is not clear how the rows in salesperson_skill should be filled when a sales-
person has different numbers of sales and technical skills. Should special
blank values be used for the missing skills, should disjointed rows be filled
with either sales or technical skills but not both, or should a cross product of all
combinations of sales and technical skills be constructed? All these alternatives
have problems with redundancy or complex rules for updating, or both.
The solution is to replace salesperson_skill with two separate tables, as
follows:
CREATE TABLE salesperson_sales_skill (
salesperson_id INTEGER NOT NULL REFERENCES salesperson,
sales_skill_id INTEGER NOT NULL REFERENCES sales_skill,
PRIMARY KEY ( salesperson_id, sales_skill_id ) );

Potrebbero piacerti anche