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.

Orders Table<br />

(Order ID Column)<br />

Figure 6-1<br />

Order ID<br />

Referential Integrity Constraints<br />

1<br />

2<br />

3<br />

3<br />

4<br />

4<br />

4<br />

5<br />

Referential<br />

Integrity<br />

Constraint<br />

Line Item<br />

1<br />

1<br />

1<br />

Referential integrity constraints are created when a value in one column must match the value in another<br />

column — in either the same table or, far more typically, a different table.<br />

Let’s say that we are taking orders for a product and that we accept credit cards. In order to be paid by<br />

the credit card company, we need to have some form of merchant agreement with that company. We<br />

don’t want our employees to take credit cards from companies that aren’t going to pay us back. That’s<br />

where referential integrity comes in — it allows us to build what we would call a domain or lookup table.<br />

A domain table is a table whose sole purpose in life is to provide a limited list (often called a domain list)<br />

of acceptable values. In our case, we might build a table that looks something like this:<br />

CreditCardID CreditCard<br />

1 VISA<br />

2 MasterCard<br />

3 Discover Card<br />

4 American Express<br />

2<br />

1<br />

2<br />

3<br />

1<br />

Domain<br />

Constraint<br />

Part Number<br />

0R2400<br />

3I8764<br />

2P9500<br />

3X5436<br />

1R5564<br />

8H0805<br />

3H6665<br />

7Y0024<br />

Chapter 6: Constraints<br />

Unit Price<br />

45.00<br />

75.36<br />

98.50<br />

12.00<br />

.98<br />

457.00<br />

65.00<br />

26.75<br />

Entity<br />

Constraint<br />

155

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

Saved successfully!

Ooh no, something went wrong!