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

OK, so are you storing information on whether your vendor is a corporation or not? You had better be<br />

if you are subject to U.S. tax law (1099 reporting). So you turn around and say that you can handle<br />

that, and the customer replies, “Great! Can you print that out along with their address as of the end of<br />

the year?”<br />

Oops — I’m betting that you don’t have past addresses, or at the very least, aren’t storing the date<br />

that the address changed. In short, you never know what a user of your system is going to ask for —<br />

try and make sure you have it. Just keep in mind that you don’t want to be moving unnecessary<br />

amounts of data up and down your network wire (see my comments on choosing a data type). If<br />

you’re storing the data just for posterity, then make sure you don’t put it in any of your application’s<br />

SELECT statements if it isn’t needed (actually, this should be your policy regardless of why you’re<br />

storing the data).<br />

Drawing Up a Quick Example<br />

Let’s walk quickly through a process of designing the invoicing database that we’ve already started with<br />

during our section on normalization. For the most part, we’re going to just be applying the diagramming<br />

tools to what we’ve already designed, but we’ll also toss in a few new issues to show how they affect<br />

our design.<br />

Creating the Database<br />

250<br />

If you think that there may be legal ramifications either way (both in keeping it and<br />

in getting rid of it), consult your attorney. Sometimes you’re legally obligated to<br />

keep data a certain amount of time; other times it’s best to get rid of information as<br />

soon as legally possible.<br />

Unlike a lot of the third-party diagramming tools out there, the <strong>SQL</strong> <strong>Server</strong> diagramming tools will not<br />

create the database for you — you have to already have it created in order to get as far as having the diagram<br />

available to work with.<br />

We’re not going to be playing with any data to speak of, so just create a small database called Invoice. I’ll<br />

go ahead and use the dialog in the Management Studio for the sake of this example.<br />

After right-clicking on the Databases node of my server and selecting New Database, I enter information<br />

in for a database called Invoice that is set up as 3MB in size.<br />

Since we’ve already had a chapter on creating databases (and for the sake of brevity), I’m just going to<br />

accept the defaults on all the other options, as shown in Figure 8-23.

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

Saved successfully!

Ooh no, something went wrong!