DBCC CHECKCONSTRAINTS in Microsoft SQL Server

DBCC CHECKCONSTRAINTS

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

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.