Relationship Guide Primary and Foreign Keys

Relationship Guide Primary and Foreign Keys

Supplement 1 MS SQL SERVER 2005Relationships

MS SQL SERVER 2005

Relationship Guide – Primary and Foreign Keys

  1. Drag and drop your related fields as you do in MS Access

  1. Make sure the primary and foreign key are the same data types.

Note the Foreign Key Relationships setting you can activate. This takes care of the integrity of our keys. Further explanations of each are provided further down the page.

Selected Relationship

Lists existing relationships. Select a relationship to show its properties in the grid to the right. If the list is empty, no relationships have been defined for the table.

Add

Create a new relationship. The Tables and Columns Specifications must be set before the relationship will be valid.

Delete

Delete the relationship selected in the Selected Relationships list. To cancel the addition of a relationship, use this button to remove the relationship.

General Category

Expand to show Check Existing Data on Creation or RE-Enabling and Tables and Columns Specifications.

Check Existing Data on Creation or Re-Enabling

Verify all existing data in the table before the constraint was created or re-enabled, against the constraint.

Tables and Columns Specifications Category

Expand to show which columns from which tables act as the foreign key and primary (or unique) key in the relationship. To edit or define these values, click the ellipsis button (…) to the right of the property field.

Foreign Key Base Table

Shows which table contains the column acting as a foreign key in the selected relationship.

Foreign Key Columns

Shows which column acts as a foreign key in the selected relationship.

Primary/Unique Key Base Table

Shows which table contains the column acting as a primary (or unique) key in the selected relationship.

Primary/Unique Key Columns

Shows which column acts as a primary (or unique) key in the selected relationship.

Identity Category

Expand to show the property fields for Name and Description.

Name

Shows the name of the relationship. When a new relationship is created, it is given a default name based on the table in the active window in Table Designer. You can change the name at any time.

Description

Describe the relationship. To write a more detailed description, click Description and then click the ellipsis (...) that appears to the right of the property field. This provides a larger area in which to write text.

Table Designer Category

Expand to show information for Check Existing Data on Creation or Re-Enabling and Enforce for Replication.

Enforce For Replication

Indicates whether to enforce the constraint when a replication agent performs an insert, update, or delete on this table. For more information, see Controlling Constraints, Identities, and Triggers with NOT FOR REPLICATION.

Enforce Foreign Key Constraint

Specify whether changes are allowed to the data of the columns in the relationship if those changes would invalidate the integrity of the foreign key relationship. Choose Yes if you do not want to allow such changes, and choose No if you do want to allow them.

INSERT and UPDATE Specification Category

Expand to show information for the Delete Rule and the Update Rule for the relationship.

Delete Rule

Specify what happens if a user tries to delete a row with data that is involved in a foreign key relationship:

  • No Action An error message tells the user that the deletion is not allowed and the DELETE is rolled back.
  • Cascade Deletes all rows containing data involved in the foreign key relationship.
  • Set Null Sets the value to null if all foreign key columns for the table can accept null values. Applies to SQL Server 2005 only.
  • Set Default Sets the value to the default value defined for the column if all foreign key columns for the table have defaults defined for them. Applies to SQL Server 2005 only.

Update Rule

Specify what happens if a user tries to update a row with data that is involved in a foreign key relationship:

  • No Action An error message tells the user that the deletion is not allowed and the DELETE is rolled back.
  • Cascade Deletes all rows containing data involved in the foreign key relationship.
  • Set Null Sets the value to null if all foreign key columns for the table can accept null values. Applies to SQL Server 2005 only.
  • Set Default Sets the value to the default value defined for the column if all foreign key columns for the table have defaults defined for them. Applies to SQL Server 2005 only.