Partilhar via


REFERENTIAL_CONSTRAINTS (Transact-SQL)

Returns one row for each FOREIGN KEY constraint in the current database. This information schema view returns information about the objects to which the current user has permissions.

To retrieve information from these views, specify the fully qualified name of **INFORMATION_SCHEMA.**view_name.

Important

This feature has changed from earlier versions of SQL Server. For more information, see Behavior Changes to Database Engine Features in SQL Server 2005.

Column name Data type Description

CONSTRAINT_CATALOG

nvarchar(128)

Constraint qualifier.

CONSTRAINT_SCHEMA

nvarchar(128)

Name of schema that contains the constraint.

CONSTRAINT_NAME

sysname

Constraint name.

UNIQUE_CONSTRAINT_CATALOG

nvarchar(128)

UNIQUE constraint qualifier.

UNIQUE_CONSTRAINT_SCHEMA

nvarchar(128)

Name of schema that contains the UNIQUE constraint.

UNIQUE_CONSTRAINT_NAME

sysname

UNIQUE constraint.

MATCH_OPTION

varchar(7)

Referential constraint-matching conditions. Always returns SIMPLE. This means that no match is defined. The condition is considered a match when one of the following is true:

  • At least one value in the foreign key column is NULL.
  • All values in the foreign key column are not NULL, and there is a row in the primary key table that has the same key.

UPDATE_RULE

varchar(11)

Action taken when a Transact-SQL statement violates the referential integrity that is defined by this constraint.

Returns one of the following:

  • NO ACTION
  • CASCADE
  • SET NULL
  • SET DEFAULT

If NO ACTION is specified on ON UPDATE for this constraint, the update of the primary key that is referenced in the constraint will not be propagated to the foreign key. If such an update of a primary key will cause a referential integrity violation because at least one foreign key contains the same value, SQL Server will not make any change to the parent and referring tables. SQL Server also will raise an error.

If CASCADE is specified on ON UPDATE for this constraint, any change to the primary key value is automatically propagated to the foreign key value.

DELETE_RULE

varchar(11)

Action taken when a Transact-SQL statement violates referential integrity defined by this constraint.

Returns one of the following:

  • NO ACTION
  • CASCADE
  • SET NULL
  • SET DEFAULT

If NO ACTION is specified on ON DELETE for this constraint, the delete on the primary key that is referenced in the constraint will not be propagated to the foreign key. If such a delete of a primary key will cause a referential integrity violation because at least one foreign key contains the same value, SQL Server will not make any change to the parent and referring tables. SQL Server also will raise an error.

If CASCADE is specified on ON DELETE on this constraint, any change to the primary key value is automatically propagated to the foreign key value.

See Also

Reference

System Views (Transact-SQL)
Information Schema Views (Transact-SQL)
sys.indexes (Transact-SQL)
sys.objects (Transact-SQL)
sys.foreign_keys (Transact-SQL)

Other Resources

Querying the SQL Server System Catalog

Help and Information

Getting SQL Server 2005 Assistance