Beginning Microsoft SQL Server 2008 ... - S3 Tech Training

Beginning Microsoft SQL Server 2008 ... - S3 Tech Training Beginning Microsoft SQL Server 2008 ... - S3 Tech Training

cdn.s3techtraining.com
from cdn.s3techtraining.com More from this publisher
17.06.2013 Views

Chapter 8: Being Normal: Normalization and Other Basic Design Issues OK, so are you storing information on whether your vendor is a corporation or not? You had better be if you are subject to U.S. tax law (1099 reporting). So you turn around and say that you can handle that, and the customer replies, “Great! Can you print that out along with their address as of the end of the year?” Oops — I’m betting that you don’t have past addresses, or at the very least, aren’t storing the date that the address changed. In short, you never know what a user of your system is going to ask for — try and make sure you have it. Just keep in mind that you don’t want to be moving unnecessary amounts of data up and down your network wire (see my comments on choosing a data type). If you’re storing the data just for posterity, then make sure you don’t put it in any of your application’s SELECT statements if it isn’t needed (actually, this should be your policy regardless of why you’re storing the data). Drawing Up a Quick Example Let’s walk quickly through a process of designing the invoicing database that we’ve already started with during our section on normalization. For the most part, we’re going to just be applying the diagramming tools to what we’ve already designed, but we’ll also toss in a few new issues to show how they affect our design. Creating the Database 250 If you think that there may be legal ramifications either way (both in keeping it and in getting rid of it), consult your attorney. Sometimes you’re legally obligated to keep data a certain amount of time; other times it’s best to get rid of information as soon as legally possible. Unlike a lot of the third-party diagramming tools out there, the SQL Server diagramming tools will not create the database for you — you have to already have it created in order to get as far as having the diagram available to work with. We’re not going to be playing with any data to speak of, so just create a small database called Invoice. I’ll go ahead and use the dialog in the Management Studio for the sake of this example. After right-clicking on the Databases node of my server and selecting New Database, I enter information in for a database called Invoice that is set up as 3MB in size. Since we’ve already had a chapter on creating databases (and for the sake of brevity), I’m just going to accept the defaults on all the other options, as shown in Figure 8-23.

Chapter 8: Being Normal: Normalization and Other Basic Design Issues Figure 8-23 Adding the Diagram and Our Initial Tables As we did when creating our AdventureWorks2008 diagram, expand the node for our database (it should have been added underneath the Databases node, but you may need to right click the databases node and choose “Refresh”) and accept the dialog asking if you want to add the objects needed to support diagramming. Then right-click on the Diagrams node and select New Database Diagram. The Add Table dialog pops up, but since there are no user tables in our database, we’ll just want to click Close so we wind up with a clean sheet. Now we’re ready to start adding new tables. You can either click the New Table icon on the toolbar, or right-click anywhere in the diagram and select New Table. Let’s start off by adding in the Orders table, as shown in Figure 8-24. Figure 8-24 251

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

Figure 8-23<br />

Adding the Diagram and Our Initial Tables<br />

As we did when creating our AdventureWorks<strong>2008</strong> diagram, expand the node for our database (it should<br />

have been added underneath the Databases node, but you may need to right click the databases node<br />

and choose “Refresh”) and accept the dialog asking if you want to add the objects needed to support diagramming.<br />

Then right-click on the Diagrams node and select New Database Diagram. The Add Table dialog<br />

pops up, but since there are no user tables in our database, we’ll just want to click Close so we wind<br />

up with a clean sheet.<br />

Now we’re ready to start adding new tables. You can either click the New Table icon on the toolbar, or<br />

right-click anywhere in the diagram and select New Table. Let’s start off by adding in the Orders table,<br />

as shown in Figure 8-24.<br />

Figure 8-24<br />

251

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

Saved successfully!

Ooh no, something went wrong!