다음을 통해 공유


How to: Modify Foreign Key Relationships

Modify the foreign key side of a relationship if you want to change which columns are related to columns in the primary key table.

Note

A new version of Table Designer appears for databases in the SQL Server 2012 format. This topic describes the old version of Table Designer, which you use with databases in earlier formats of SQL Server.

In the new version, you can change a table definition through a graphical interface or directly in a script pane. If you use the graphical interface, the table’s definition is automatically updated in the script pane. To apply the SQL code in the script pane, choose the Update button. For more information about the new version, see How to: Create Database Objects Using Table Designer.

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.

To modify a foreign key

  1. In Server Explorer, select the table with the foreign key, and from the Data menu click Open Table Definition.

  2. The table opens in Table Designer.

  3. From the Table Designer menu, click Relationships.

  4. In the Foreign Key Relationships dialog box, select the relationship in the Selected Relationship list.

  5. In the grid, click the Tables and Columns Specifications and click the ellipses (…) to the right of the property.

  6. In the Tables and Columns dialog box, select a different table column from the list. The foreign key column must match the data type and size of the primary key column, with these exceptions:

    • A char column or sysname column can relate to a varchar column.

    • A binary column can relate to a varbinary column.

    • A user-defined data type can relate to its base type.

Any changes you make to the relationship's properties take effect as soon as you move outside the grid in Table Designer. The constraint is updated in the database when you save your table.

See Also

Other Resources

Working with Keys

Working with Constraints