DBCC CHECKCONSTRAINTS in Microsoft SQL Server

Checks the integrity of a specified constraint or all constraints on a specified table in SQL Server

Checks the integrity of a specified constraint or all constraints on a specified table.

Syntax:

DBCC CHECKCONSTRAINTS     [( 'table_name' | 'constraint_name'      )]
[ WITH { ALL_ERRORMSGS | ALL_CONSTRAINTS } ]

DBCC CHECKCONSTRAINTS constructs and executes a query for all foreign key constraints and check constraints on a table.

A. Check a table.
This example checks the constraint integrity of the authors table in the pubs database.

DBCC CHECKCONSTRAINTS ('authors')
GO


B. Check a specific constraint
This example checks the integrity of the PartNo_FKey constraint. The constraint name uniquely identifies the table it is declared upon.

DBCC CHECKCONSTRAINTS ('PartNo_Fkey')
GO


C. Check all enabled and disabled constraints on all tables
This example checks the integrity of all enabled and disabled constraints on all tables in the current database.

DBCC CHECKCONSTRAINTS WITH ALL_CONSTRAINTS
GO

Leave a Reply