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 />

218<br />

A first pass on this might have one entity: Orders.<br />

As you become more experienced at normalization, your first pass at something like this is probably<br />

going to yield you quite a few more entities right from the beginning. For now though, we’ll just take<br />

this one and see how the normalization process shows us the others that we need.<br />

Assuming you’ve got your concepts down of what you want your entities to be, the next place to go is to<br />

figure out your beginning columns and, from there, a primary key. Remember that a primary key provides<br />

a unique identifier for each row.<br />

We can peruse our list of columns and come up with key candidates. Your list of key candidates should<br />

include any column that can potentially be used to uniquely identify each row in your entity. There is,<br />

otherwise, no hard and fast rule on what column has to be the primary key (this is one of many reasons<br />

you’ll see such wide variation in how people design databases that are meant to contain the same basic<br />

information). In some cases, you will not be able to find even one candidate key, and you will need to<br />

make one up (remember Identity and rowguid() columns?).<br />

We already created an Orders table in the previous chapter, but for example purposes let’s take a look at<br />

a very common implementation of an Orders table in the old flat file design:<br />

Orders<br />

OrderNo<br />

CustomerNo<br />

CustomerName<br />

CustomerAddress<br />

CustomerCity<br />

CustomerState<br />

CustomerZip<br />

OrderDate<br />

ItemsOrdered<br />

Total<br />

Since this is an Orders table, and logically, an order number is meant to be one to an order, I’m going go<br />

with OrderNo as my primary key.<br />

OK, so now we have a basic entity. Nothing about this entity cares about the ordering of columns (tables<br />

are, by convention, usually organized as having the primary key as the first column(s), but, technically<br />

speaking, it doesn’t have to be that way). Nothing in the basic makeup of this table cares about the<br />

ordering of the rows. The table, at least superficially, describes just one entity. In short, we’re ready to<br />

begin our normalization process (actually, we sort of already have).

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

Saved successfully!

Ooh no, something went wrong!