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

Note that, for either example, the implementation of referential integrity is the same — each of the base<br />

tables (the tables that hold the underlying data and have the many-to-many relationship) has a one-to-many<br />

relationship with the associate table. This can be done via either a trigger or a FOREIGN KEY constraint.<br />

Diagramming<br />

Entity Relationship Diagrams (ERDs) are an important tool in good database design. Small databases<br />

can usually be easily created from a few scripts and implemented directly without drawing things out at<br />

all. The larger your database gets, however, the faster it becomes very problematic to just do things “in<br />

your head.” ERDs solve a ton of problems because they allow you to quickly visualize and understand<br />

both the entities and their relationships.<br />

Fortunately, <strong>SQL</strong> <strong>Server</strong> includes a very basic diagramming tool that you can use as a starting point for<br />

building rudimentary ERDs.<br />

Before the first time I wrote this topic, I debated for a long while about how I wanted to handle this. On<br />

one hand, serious ER diagramming is usually done with an application that is specifically designed to<br />

be an ER diagramming tool. These tools almost always support at least one of a couple of industry standard<br />

diagramming methods. Even some of the more mass-market diagramming tools — such as Visio —<br />

support a couple of ERD methodologies. <strong>SQL</strong> <strong>Server</strong> has an ERD tool built in, and therein lies the problem.<br />

The tools that are included with <strong>SQL</strong> <strong>Server</strong> <strong>2008</strong> are a variation on a toolset and diagramming<br />

methodology that <strong>Microsoft</strong> has used in a number of tools for many years now. The problem is that they do<br />

not compete with any ERD standard that I’ve seen anywhere else. As I’ve done every time I’ve written on<br />

this topic, I’ve decided to stick with what I know you have — the built-in tools. I do, however, encourage<br />

you to examine the commercially available ERD tools out there to see the rich things that they offer to<br />

simplify your database design efforts.<br />

You can open up <strong>SQL</strong> <strong>Server</strong>’s built-in tools by navigating to the Diagrams node of the database you<br />

want to build a diagram for (expand your server first, then the database). Some of what we are going to<br />

see you’ll find familiar — some of the dialogs are the same as we saw in Chapter 5 when we were creating<br />

tables.<br />

The <strong>SQL</strong> <strong>Server</strong> diagramming tools don’t give you all that many options, so you’ll find that you’ll get to<br />

know them fairly quickly. Indeed, if you’re familiar with the relationship editor in Access, then much of<br />

the <strong>SQL</strong> <strong>Server</strong> tools will seem very familiar.<br />

Try It Out Diagramming<br />

Let’s start by creating our first diagram. You can create your new diagram by right-clicking the Diagrams<br />

node underneath the AdventureWorks<strong>2008</strong> database and choosing the New Database Diagram<br />

option.<br />

As we saw back in Chapter 5, you may (if it’s the first time you’ve tried to create a diagram) see a dialog<br />

come up warning you that some of the objects needed to support diagramming aren’t in the database<br />

and asking if you want to create them — choose Yes.<br />

<strong>SQL</strong> <strong>Server</strong> starts us out with the same Add Table dialog (see Figure 8-7) we saw in Chapter 5 — the<br />

only thing different is the tables listed.<br />

235

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

Saved successfully!

Ooh no, something went wrong!