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

254<br />

UnitPrice is relatively easy: As this field is going to hold a monetary value, its data type hints at<br />

money. Be careful with this though. How many decimal places do you really need? U.S. developers are<br />

going to tend toward thinking they only need two (several currencies often trade in more decimal places),<br />

but what about commodity items? For example, gasoline is generally sold in fractions of a cent. The<br />

money data type handles 4 decimal places, which meets most currency needs.<br />

Moving along, we’re again (no surprise here) considering all data fields to be required. No, we’re not<br />

allowing nulls anywhere.<br />

No defaults seem to make sense for this table, so we’re skipping that part also.<br />

Identity? The temptation might be to mark OrderID as an identity column again. Don’t do that!<br />

Remember that OrderID is a value that we’re going to match to a column in another table. That table<br />

will already have a value (as it happens, set by identity, but it didn’t necessarily have to be that way),<br />

so setting our column to identity would cause a collision. We would be told that we can’t do our insert<br />

because we’re trying to set an identity value. All the other columns either get their data from another<br />

table or require user input of the data. IsRowGuid does not apply again.<br />

That takes us to our Products and Customers tables, as shown in Figures 8-26 and 8-27 respectively.<br />

Figure 8-26<br />

Figure 8-27<br />

Let’s hit the highlights on the choices here and move on.<br />

PartNo has been defined by the data that we saw when we were looking at normalization. It’s a numeric,<br />

followed by an alpha, followed by four numerics. That’s six characters, and it seems to be fixed. We would<br />

want to hold the customer to the cross about the notion that the size of the part number can’t get any<br />

larger but, assuming that’s OK, we’ll go with a char(6) here. That’s because a char takes up slightly<br />

less overhead than a varchar, and we know that the length is going to always remain the same (this<br />

means that there’s no benefit from the variable size).

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

Saved successfully!

Ooh no, something went wrong!