It seems that some scripts generated by Enterprise Manager* (or not, it doesn't matter) created check constraints WITH NOCHECK.
Now when anyone modifies the table, SQL Server is stumbling across failed check constraints, and throwing errors.
Can i make SQL go through all its check constraints, and check them?
Running:
sp_msforeachtable 'ALTER TABLE ? CHECK CONSTRAINT all'
only enables previously disabled check constraints, it doesn't actually check them.
Footnotes
* SQL Server 2000
Found it:
Checks all constraints on all tables in the current database, whether the constraint is enabled or not:
To check only enabled constraints:
DBCC CHECKCONSTRAINTS WITH ALL_CONSTRAINTS won't actually make your constraints trusted. It will report any rows that violate the constraints. To actually make all of your constraints trusted, you can do the following:
In SQL Server 2000 you can find any untrusted constraints with:
Constraints are then re-reenabled with check:
Note: on the last statement, the
WITH CHECK CHECK
is not a typo. The "WITH CHECK" will check all table data to ensure there are not violations, and will make the constraint trusted, while the check will make sure the constraints is enabled.See also: http://sqlblog.com/blogs/tibor_karaszi/archive/2008/01/12/non-trusted-constraints.aspx
http://sqlblog.com/blogs/tibor_karaszi/archive/2008/01/12/non-trusted-constraints-and-performance.aspx
do this:
Explanation: Can you trust your constraints?