Datasheet
17. Click the Add button in the Foreign Key Relationships dialog box to add another relationship.
In the Properties window, click the Tables and Columns Specification property and then click
the elipse button for this property to display the Tables and Columns dialog box.
18. In the Tables and Columns dialog box, select the Projects table in the Primary key table combo
box and then click in the empty row under this combo box and select ProjectID in the combo
box that is displayed. In the first row under the Foreign key table column, select ProjectID in the
combo box that is displayed there and then click OK to return to the Foreign Key Relationships
dialog box.
19. Click Close to close the Foreign Key Relationships dialog box. Next, click the Save icon on the
toolbar to save the GroupProjects table. You are prompted with the tables that will be saved in
your database, which are the tables affected by this relationship. Click Yes to proceed.
20. Using Table 1-8, repeat Steps 14 through 19 to create the rest of the foreign key relationships in
your database.
Table 1-8: Foreign Key Relationships
Foreign Key Table Foreign Key Primary Key Table Primary Key
Users ManagerID Users UserID
Users GroupID Groups GroupID
Users RoleID Roles RoleID
TimeSheets UserID Users UserID
TimeSheets ManagerID Users UserID
TimeSheetItems TimeSheetID TimeSheets TimeSheetID
TimeSheetItems ProjectID Projects ProjectID
How It Works
Using Visual Studio 2005, you connect to the SQL Server instance that contains your ProjectTimeTracker
database in the Server Explorer window using a Data Connection. You are then able to use Visual Studio
2005 to create the tables within your database.
During the process of creating your tables, you set the primary key on each table, effectively creating a
clustered index on the table based on the primary key. After all the tables are created, you create the for-
eign key relationships between the tables, joining the foreign key in one table to the primary key in
another table. This causes a relationship to be formed between your tables and enforces the values that
can be inserted into a table containing a foreign key. The table containing a foreign key will not allow
you to insert a value in the foreign key column that does not exist in the primary key column of the
primary table.
24
Chapter 1
04_58894x ch01.qxd 10/13/05 5:54 PM Page 24