Constraint Class

Represents a constraint that can be enforced on one or more DataColumn objects.

Namespace: System.Data
Assembly: System.Data (in

public ref class Constraint abstract
public abstract class Constraint
public abstract class Constraint

A constraint is a rule used to maintain the integrity of the data in the DataTable. For example, when you delete a value that is used in one or more related tables, a ForeignKeyConstraint determines whether the values in the related tables are also deleted, set to null values, set to default values, or whether no action occurs. A UniqueConstraint, on the other hand, just makes sure that all values within a particular table are unique. For more information, see Adding Constraints to a Table.

A base Constraint constructor is not used. Primary or unique key constraints are created by using the UniqueConstraint constructor, and foreign key constraints are created by using the ForeignKeyConstraint constructor.

The following example examines the collection of constraints for a DataTable and determines whether each constraint is a UniqueConstraint or a ForeignKeyConstraint. The properties of the constraint are then displayed.

No code example is currently available or this language may not be supported.

This type is safe for multithreaded read operations. You must synchronize any write operations.

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

Community Additions