Share via


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

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

The dialog boxes and menu commands you see might differ from those described in Help depending on your active settings or edition. To change your settings, choose Import and Export Settings on the Tools menu. For more information, see Visual Studio Settings.

To check existing data when creating a relationship

  1. In Server Explorer, right-click the table that will be on the foreign-key side of the relationship.

    The table opens in Table Designer.

  2. From the Table Designer menu, click Relationships.

  3. 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.

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

  5. In the grid, click Check Existing Data On Creation.

  6. 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.

See Also

Other Resources

Working with Relationships

Working with Constraints