Sql-server – Should you run DBCC CHECKCONSTRAINTS regularly

sql server

In my database, no one is adding, removing, or disabling constraints outside of patches and releases. All constraints are enabled and trusted. There is a regular check for untrusted or disabled constraints in case one were to be accidentally introduced. DBCC CHECKDB is also run on a regular basis to check for corruption.

Is there a benefit to running DBCC CHECKCONSTRAINTS just as regularly as DBCC CHECKDB? Or am I causing unnecessary work? When should DBCC CHECKCONSTRAINTS usually be run?

Best Answer

From Microsoft documentation:

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

You only urn this after repairing a database and against the objects with constraints to confirm those constraints are still valid.

Quote from The Accidental DBA (Day 13 of 30): Consistency Checking by Erin Stellato

CHECKCONSTRAINTS is a command to verify that data in a column or table adheres to the defined constraints. This command should be run any time you run CHECKDB with the REPAIR_ALLOW_DATA_LOSS option. Repair in DBCC will fix corruption, and it doesn’t take constraints into consideration; it just alters data structures as needed so that data can be read and modified. As such, after running repair, constraint violations can exist, and you need to run CHECKCONSTRAINTS for the entire database to find them.