Add Relations
The Add Relations dialog box in Server Explorer in Visual Studio enables you to create primary key and foreign key relations in SQL Server Compact.
Options
Relation Name
Specify a name for the relation.
Update Rule
Enables you to update rules by using the following options:
NO ACTION, CASCADE, SET NULL, SET Default
If you specify NO ACTION, SQL Server Compact returns an error, and the update action on the referenced row in the parent table is rolled back.
If you specify the CASCADE option and the corresponding referenced row is updated in the parent table, the row is updated in the referencing table.
For example, you might have two tables, A and B, in a database. Table A has a referential relationship with table B: The A.ItemID foreign key references the B.ItemID primary key.
If an UPDATE statement is executed on a row in table B and an ON UPDATE CASCADE action is specified for A.ItemID, SQL Server Compact checks for one or more dependent rows in table A. If any exist, the dependent rows in table A are updated and the row that is referenced in table B is updated.
Delete Rule
Enables you to delete rules by using the following options:
NO ACTION, CASCADE, SET NULL, SET Default
If you specify NO ACTION, SQL Server Compact returns an error, and the delete action on the referenced row in the parent table is rolled back.
If you specify the CASCADE option and the corresponding referenced row is deleted in the parent table, the row is deleted in the referencing table.
For example, you might have two tables, A and B, in a database. Table A has a referential relationship with table B: The A.ItemID foreign key references the B.ItemID primary key.
If an UPDATE statement is executed on a row in table B and an ON UPDATE CASCADE action is specified for A.ItemID, SQL Server Compact checks for one or more dependent rows in table A. If any exist, the dependent rows in table A are deleted and the row referenced in table B is deleted.
Primary Key Table
Select the primary key table.
Foreign key table
Select the foreign key table.
Primary Key Table Column
Select the columns under the Primary key table list.
Foreign Key Table Column
Select the columns under the Foreign key table list.
Add Columns
Click Add Column to add the list of Primary key table columns and Foreign key table columns to the Manage Rules in Relation group box.
Delete Column
Click Delete to remove the selected Primary key table columns and Foreign key table columns that were added to the Manage Rules in Relation group box.
Add Relation
Click the Add Relation button to create the relation between the primary key table columns and the foreign key table columns that appear in the Manage Rules in Relation group box.