17.06.2013 Views

Beginning Microsoft SQL Server 2008 ... - S3 Tech Training

Beginning Microsoft SQL Server 2008 ... - S3 Tech Training

Beginning Microsoft SQL Server 2008 ... - S3 Tech Training

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 8: Being Normal: Normalization and Other Basic Design Issues<br />

Figure 8-2<br />

At this point, we meet our criteria for first normal form. We have no repeating groups of data, and all<br />

columns are atomic. We do have issues with data having to be repeated within a column (because it’s the<br />

same for all rows for that primary key), but we’ll deal with that shortly.<br />

The Second Normal Form<br />

222<br />

Order No<br />

(PK)<br />

100<br />

100<br />

100<br />

100<br />

101<br />

102<br />

102<br />

102<br />

103<br />

103<br />

103<br />

Line Item<br />

(PK)<br />

1<br />

2<br />

3<br />

4<br />

1<br />

1<br />

2<br />

3<br />

1<br />

2<br />

3<br />

Rather than create another column as we did here, we also could have taken the<br />

approach of making PartNo part of our primary key. The fallout from this would<br />

have been that we could not have had the same part number appear twice in the<br />

same order. We’ll briefly discuss keys based on more than one column — or composite<br />

keys — in our next chapter.<br />

The next phase in normalization is to go to the second normal form (2NF). Second normal form further<br />

reduces the incidence of repeated data (not necessarily groups).<br />

Second normal form has two rules to it:<br />

Order Date Customer No Part No Description Qty Unit Price Total Price Wt.<br />

1/1/1999<br />

1/1/1999<br />

1/1/1999<br />

1/1/1999<br />

1/1/1999<br />

1/1/1999<br />

1/1/1999<br />

1/1/1999<br />

1/2/1999<br />

1/2/1999<br />

1/2/1999<br />

54545<br />

54545<br />

54545<br />

54545<br />

12000<br />

66651<br />

66651<br />

66651<br />

54545<br />

54545<br />

54545<br />

1A4536<br />

0R2400<br />

0R2403<br />

4I5436<br />

3X9567<br />

8G9200<br />

8G5437<br />

3H6250<br />

8G9200<br />

2P5523<br />

3X9567<br />

❑ The table must meet the rules for first normal form. (Normalization is a building block kind of<br />

process — you can’t stack the third block on if you don’t have the first two there already.)<br />

❑ Each column must depend on the whole key.<br />

Flange<br />

Injector<br />

Injector<br />

Head<br />

Pump<br />

Fan<br />

Fan<br />

Control<br />

Fan<br />

Housing<br />

Pump<br />

Our example has a problem — actually, it has a couple of them — in this area. Let’s look at the first normal<br />

form version of our Orders table again (Figure 8-2) — is every column dependent on the whole<br />

key? Are there any that need only part of the key?<br />

The answers are no and yes respectively. There are two columns that only depend only on the OrderNo<br />

column — not the LineItem column. The columns in question are OrderDate and CustomerNo; both are<br />

the same for the entire order regardless of how many line items there are. Dealing with these requires<br />

that we introduce yet another table. At this point, we run across the concept of a header vs. a detail table<br />

for the first time.<br />

5<br />

4<br />

4<br />

1<br />

1<br />

7<br />

1<br />

1<br />

40<br />

1<br />

1<br />

15<br />

27<br />

29<br />

750<br />

62.50<br />

12<br />

15<br />

32<br />

12<br />

165<br />

42<br />

75<br />

108<br />

116<br />

750<br />

62.50<br />

84<br />

15<br />

32<br />

480<br />

165<br />

42<br />

6<br />

.5<br />

.5<br />

3<br />

5<br />

3<br />

3<br />

5<br />

3<br />

1<br />

5

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!