Share via


Foreign Key Relationships Dialog Box

Use this dialog box to create or modify relationships between tables in your database. In a foreign key relationship, foreign key constraints work in conjunction with primary key or unique constraints to enforce referential integrity among specified tables. For example, you can place a foreign key constraint on the ProductID column in the Order_Details table to ensure that a value entered in that column matches an existing value in the ProductID column of the Products table.

To access this dialog box, open the table definition for the table with the foreign key, right-click the table definition grid, and click Relationships.

Note

Your computer might show different names or locations for some of the Visual Studio user interface elements in the following instructions. The Visual Studio edition that you have and the settings that you use determine these elements. For more information, see Customizing Development Settings in Visual Studio.

  • 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 Button
    Creates a new relationship. The Tables and Columns Specifications must be set before the relationship will be valid.

  • Delete Button
    Deletes the relationship selected in the Selected Relationships list.

  • General Category
    Expands to show Check Existing Data on Creation or RE-Enabling and Tables and Columns Specifications.

  • Check Existing Data on Creation or Re-Enabling
    Indicates whether all data that exist in the table before the constraint was created or re-enabled is verified against the constraint.

  • Tables and Columns Specifications Category
    Expands 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 (…) 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
    Expands 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
    Provides a place to 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
    Expands to show information for Check Existing Data on Creation or Re-Enabling and Enforce for Replication.

  • Enforce for Replication
    Indicates whether the constraint is enforced when the table is replicated into a different database.

  • Enforce Foreign Key Constraint
    Indicates whether changes to the data of the columns in the relationship are allowed 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
    Expands to show information for the Delete Rule and the Update Rule for the relationship.

  • Delete Rule
    Specifies what happens if an end user of the database tries to delete a row with data that is involved in a foreign key relationship. If set to:

    • 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 only to SQL Server 2005 and SQL Server 2008.

    • 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 only to SQL Server 2005 and SQL Server 2008.

  • Update Rule
    Specifies what happens if a user of the database tries to update a row with data that is involved in a foreign key relationship. If set to:

    • 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 only to SQL Server 2005 and SQL Server 2008.

    • 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 only to SQL Server 2005 and SQL Server 2008.

See Also

Tasks

How to: Create Relationships Between Tables

Concepts

Overview of Referential Integrity

Other Resources

Working with Relationships

Working with Keys