Restricting actions performed in related tables

Action

Description

Cascade

Deletes or updates related rows. This is the default.

SetNull

Sets values in related rows to DBNull.

SetDefault

Sets values in related rows to the DefaultValue.

None

No action is taken, but an exception is raised.

illegal for non-trainer use illegal for non-trainer use

Introduction

Restricting actions performed in related tables

A foreign key constraint restricts the action performed in related tables when data in a table is either updated or deleted. For example, if a value in a row of one table is updated or deleted, and that same value is also used in one or more related tables, you can use a ForeignKeyConstraint constructor to determine what happens in the related tables.

A ForeignKeyConstraint can restrict, as well as propagate, changes to related columns. Depending on the properties set for the ForeignKeyConstraint of a column, and if the EnforceConstraints property of the DataSet is true, performing certain operations on the parent row will result in an exception. For example, if the DeleteRule property of the ForeignKeyConstraint is None, a parent row cannot be deleted if it has any child rows.

In a parent-child relationship between two columns, you establish the action to be taken by setting the DeleteRule property of the foreign key constraint to one of the values in the following table.

Action

Description

Cascade SetNull SetDefault None

Deletes or updates related rows. This is the default. Sets values in related rows to DBNull. Sets values in related rows to the DefaultValue. No action is taken, but an exception is raised

0 0

Post a comment