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

Let me reiterate the importance of being sure that your customers are really considering their future<br />

needs. The PartNo column using a simple 6-character field is an example of where you might want to<br />

be very suspicious. Part numbers are one of those things that people develop new philosophies on almost<br />

as often as my teenage daughter develops new taste in clothes. Today’s inventory manager will swear<br />

that’s all they ever intend to use and will be sincere in it, but tomorrow there’s a new inventory manager<br />

or perhaps your organization merges with another organization that uses a 10-digit numeric part number.<br />

Expanding the field isn’t that bad of a conversion, but any kind of conversion carries risks, so you want<br />

to get it right the first time.<br />

Description is one of those guessing games. Sometimes a field like this is going to be driven by your<br />

user interface requirements (don’t make it wider than can be displayed on the screen), other times you’re<br />

just going to be truly guessing at what is “enough” space. Here you use a variable-length char over a<br />

regular char for two reasons:<br />

❑ To save a little space<br />

❑ So we don’t have to deal with trailing spaces (look at the char vs. varchar data types back in<br />

Chapter 1 if you have questions on this)<br />

We haven’t used an nchar or nvarchar because this is a simple invoicing system for a U.S. business,<br />

and we’re not concerned about localization issues. If you’re dealing with a multilingual scenario, you’ll<br />

want to pay much more attention to the Unicode data types. You’ll also want to consider them if you’re<br />

storing inherently international information such as URLs, which can easily have kanji and similar characters<br />

in them.<br />

Weight is similar to Description in that it is going to be somewhat of a guess. We’ve chosen a tinyint<br />

here because our products will not be over 255 pounds. Note that we are also preventing ourselves from<br />

keeping decimal places in our weight (integers only). As we discussed back under PartNo, make sure<br />

you consider your needs carefully — conservative can be great, but being over-conservative can cause a<br />

great deal of work later.<br />

We described the CustomerNo field back when we were doing the Orders table.<br />

CustomerName and CustomerAddress are pretty much the same situation as Description — the question<br />

is, how much is enough? But we need to be sure that we don’t give too much.<br />

As before, all fields are required (there will be no nulls in either table) and no defaults are called for.<br />

Identity columns also do not seem to fit the bill here as both the customer number and part number have<br />

special formats that do not lend themselves to the automatic numbering system that an identity provides.<br />

Adding the Relationships<br />

OK, to make the diagram less complicated, I’ve gone through all four of my tables and changed the view<br />

on them down to just Column Names. You can do this, too, by simply right-clicking on the table and<br />

selecting the Column Names menu choice.<br />

You should get a diagram that looks similar to Figure 8-28.<br />

255

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

Saved successfully!

Ooh no, something went wrong!