How to: Check Existing Data when Creating a Relationship
Select the option to check existing data when you create a relationship if the foreign key constraint should apply to existing data as well as to new data.
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
Some databases have different functionality for foreign key constraints. Consult your database documentation for details about how your database works with foreign key constraints.
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 check existing data when creating a relationship
In Server Explorer, right-click the table that will be on the foreign-key side of the relationship.
The table opens in Table Designer.
From the Table Designer menu, click Relationships.
In the Foreign-key Relationships dialog box, click Add.
The relationship appears in the Selected Relationship list with a system-provided name in the format FK_<tablename>_<tablename>, where tablename is the name of the foreign key table.
In the Foreign Key Relationships dialog box, select the relationship from the Selected Relationship list.
In the grid, click Check Existing Data On Creation.
Choose Yes from the drop-down list to the right of the property.
The foreign key constraint is applied when you save the table. If any constraint violations are encountered during the save process, the table cannot be saved.