188Microsoft Visual Studio 2010: A Beginner’s Guide

can have zero or more orders. A foreign key can help manage the relationship between Customer and Order.

The mechanics of creating a foreign key relationship is that you put the foreign key column in the child table, Order, and have the foreign key column refer to the primary key of the parent table, Customer. In this case, the reference is made simply by matching the integer value; if the ID number is the same in both tables, then the records are related. As shown in Figure 7-5, Order does have a CustomerID column, of type int, and we will make this the foreign key that will refer to CustomerID primary key in Customer, shown in Figure 7-3.

To create this foreign key relationship in VS, right-click the CustomerID column in the Order table and select Relationships. We’re going to create the foreign key relationship that you see in Figure 7-6.

Next, click Add, select the Tables And Columns Specific property, and click the ellipses button that appears on the far right of your selection (the ellipses does not appear until you first click “Tables And Columns Specific” below “(General)” in the Foreign Key Relationships dialog window. This will open the Tables And Columns window shown in Figure 7-7.

Figure 7-6 Managing a foreign key relationship

Page 211
Image 211
Microsoft 9GD00001 manual Managing a foreign key relationship