Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>DBCC CHECKCONSTRAINTS WITH ALL_CONSTRAINTS</strong> 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:</p> <pre><code>DBCC CHECKCONSTRAINTS WITH ALL_CONSTRAINTS --This reports any data that violates constraints. --This reports all constraints that are not trusted SELECT OBJECT_NAME(parent_object_id) AS table_name, name, is_disabled FROM sys.check_constraints WHERE is_not_trusted = 1 UNION ALL SELECT OBJECT_NAME(parent_object_id) AS table_name, name, is_disabled FROM sys.foreign_keys WHERE is_not_trusted = 1 ORDER BY table_name </code></pre> <p>In SQL Server 2000 you can find any untrusted constraints with:</p> <pre><code>--Reports all constraints that are not trusted (SQL 2000) SELECT name, type, status, (status &amp; 2048) AS IsTrusted, (status &amp; 256) AS IsEnabled, OBJECTPROPERTY(id,'CnstIsNotTrusted') as is_not_trusted, OBJECTPROPERTY(id,'CnstIsDisabled') as is_disabled FROM sysobjects WHERE type IN ('C', 'F') --C=Constraint, F=Foreign Key AND OBJECTPROPERTY(id,'CnstIsNotTrusted') &lt;&gt; 0 AND OBJECTPROPERTY(id,'CnstIsDisabled') = 0 </code></pre> <p>Constraints are then re-reenabled <em>with check</em>:</p> <pre><code>--This makes all constraints trusted -- but first anything reported by DBCC CHECKCONSTRAINTS WITH ALL_CONSTRAINTS must be fixed. exec sp_msforeachtable 'ALTER TABLE ? WITH CHECK CHECK CONSTRAINT all' </code></pre> <p><strong>Note</strong>: on the last statement, the <code>WITH CHECK CHECK</code> 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.</p> <p>See also: <a href="http://sqlblog.com/blogs/tibor_karaszi/archive/2008/01/12/non-trusted-constraints.aspx" rel="noreferrer">http://sqlblog.com/blogs/tibor_karaszi/archive/2008/01/12/non-trusted-constraints.aspx</a></p> <p><a href="http://sqlblog.com/blogs/tibor_karaszi/archive/2008/01/12/non-trusted-constraints-and-performance.aspx" rel="noreferrer">http://sqlblog.com/blogs/tibor_karaszi/archive/2008/01/12/non-trusted-constraints-and-performance.aspx</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload