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

we looked at in the previous section — the Relationships dialog for the SalesOrderHeader table is<br />

shown in Figure 8-18.<br />

Figure 8-18<br />

From here, we can edit the nature of our relationship, including such things as cascading actions, whether<br />

the foreign key is enabled or disabled (for example, if we want to deliberately add data in that violates<br />

the relationship), and even the name of the relationship.<br />

Database designers seem to vary widely in their opinion regarding names for relationships. Some don’t<br />

care what they are named, but I prefer to use a verb phrase to describe my relationships — for example,<br />

in our Customers/Orders relationship, I would probably name it CustomerHasOrders or something of<br />

that ilk. It’s nothing critical — most of the time you won’t even use it — but I find that it can be really<br />

helpful when I’m looking at a long object list or a particularly complex ER Diagram where the lines may<br />

run across the page past several unrelated entities.<br />

Adding Relationships in the Diagramming Tool<br />

Just drag and drop — it’s that easy. The only trick is making sure that you start and end your drag in the<br />

places you meant to. If in doubt, select the column(s) you’re interested in before starting your drag.<br />

Try It Out Adding a Relationship<br />

Let’s add a relationship between our new CustomerNotes table (we created it in the last section) and the<br />

Customers table — after all, if it’s a customer note we probably want to make sure that we are taking notes<br />

on a valid customer. To do this, click and hold in the gray area to the left of the CustomerID column<br />

in the Customers table, then drag your mouse until it is pointing at the CustomerID column in the<br />

CustomerNotes table. A dialog box should pop up to confirm the column mapping between the related<br />

tables (see Figure 8-19).<br />

245

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

Saved successfully!

Ooh no, something went wrong!