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

This one, however, gives us the same basic problem that we had with one-to-one relationships. It’s still<br />

that chicken or egg thing — which came first? Again, in <strong>SQL</strong> <strong>Server</strong>, the only way to implement this<br />

fully is by restricting all data to be inserted or deleted via stored procedures.<br />

One-to-Zero, One, or Many<br />

230<br />

This is the other, and perhaps even more common, form of the run-of-the-mill, average, everyday, foreign<br />

key relationship. The only real difference in implementation here is that the referencing field (the one in<br />

the table that has the foreign key constraint) is allowed to be null; that is, the fact that you have a record<br />

in the “one” table, doesn’t necessarily mean that you have any instances of matching records in the referencing<br />

table.<br />

Imagine for a moment the scenario where we track what shipper is used for orders that are shipped, but<br />

where we also have a will call counter for customer pickup. If there is a shipper, then we want to limit it<br />

to our approved list of shippers, but it’s still quite possible that there won’t be any shipper at all, as illustrated<br />

in Figure 8-4.<br />

Figure 8-4<br />

Order ID Order Date Customer ID Shipper ID Ship To Address<br />

10500<br />

10501<br />

10502<br />

Shipper ID Company Name Phone<br />

1<br />

2<br />

3<br />

1997-04-09<br />

1997-04-09<br />

1997-04-10<br />

Speedy Express<br />

United Package<br />

Federal Shipping<br />

LAMAI<br />

BLAUS<br />

PERIC<br />

A virtually identical example can be found in the AdventureWorks<strong>2008</strong> database in the relationship<br />

between Purchasing.PurchaseOrderHeader and Purchasing.ShipMethod, with the only real difference<br />

being that this is a list of companies shipping to us rather than from us.<br />

1<br />

3<br />

1<br />

(503) 5559831<br />

(503)5553199<br />

(503) 5559931<br />

1 rue Alsace-Lorraine<br />

Forsterstr 57<br />

Calle Dr. Jorge...

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

Saved successfully!

Ooh no, something went wrong!