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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

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

So, now you have second normal form. All of our columns depend on the entire key. I’m sure you won’t<br />

be surprised to hear that we still have a problem or two though — we’ll deal with them next.<br />

The Third Normal Form<br />

224<br />

This is the relative end of the line. There are technically levels of normalization beyond this, but none<br />

that get much attention outside of academic circles. We’ll look at those extremely briefly next, but first<br />

we need to finish the business at hand.<br />

I mentioned at the end of our discussion of the second normal form that we still had problems — we still<br />

haven’t reached the third normal form (3NF). The third normal form deals with the issue of having all<br />

the columns in our table not just be dependent on something — but dependent on the right thing. The<br />

third normal form has just three rules to it:<br />

❑ The table must be in 2NF (I told you this was a building block thing).<br />

❑ No column can have any dependency on any other non-key column.<br />

❑ You cannot have derived data.<br />

We already know that we’re in the second normal form, so let’s look at the other two rules.<br />

First, do we have any columns that have dependencies other than the primary key? Yes! Actually, there<br />

are a couple of columns that are dependent on the PartNo as much as, if not more than, the primary key<br />

of this table. Weight and Description are both entirely dependent on the PartNo column — we again<br />

need to split into another table.<br />

Your first tendency here might be to also lump UnitPrice into this category, and you would be partially<br />

right. The Products table that we will create here can and should have a UnitPrice column in it —<br />

but it will be of a slightly different nature. Indeed, perhaps it would be better named ListPrice, as it is<br />

the cost we have set in general for that product. The difference for the UnitPrice in the OrderDetails<br />

table is twofold. First, we may offer discounts that would change the price at time of sale. This means<br />

that the price in the OrderDetails record may be different than the planned price that you will keep<br />

in the Products table. Second, the price we plan to charge will change over time with factors such as<br />

inflation, but changes in future prices will not change what we have charged on our actual orders of the<br />

past. In other words, price is one of those odd circumstances where there are really two flavors of it —<br />

one dependent on the PartNo, and one dependent on the primary key for the OrderDetails table (in<br />

other words OrderID and LineItem).<br />

First, we need to create a new table (we’ll call it Products) to hold our part information. This new table<br />

will hold the information that we had in OrderDetails that was more dependent on PartNo than on<br />

OrderID or LineItem:<br />

PartNo (PK) Description Wt<br />

1A4536 Flange 6<br />

OR2400 Injector .5<br />

OR2403 Injector .5

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

Saved successfully!

Ooh no, something went wrong!