When you disable a constraint and enable it without explicitly stating the WITH CHECK clause, SQL Server will flag that constraint as "untrusted" because it can't count on the constraint's presence to ensure data consistency. Consequently, the constraint will be disregarded in execution plans. It's advisable to consistently employ WITH CHECK while reactivating constraints to uphold best practices.
Untrusted constraints:
SELECT
DB_NAME(),
s.name,
o.name,
i.name
FROM
sys.check_constraints i
INNER JOIN sys.objects o ON i.parent_object_id = o.object_id
INNER JOIN sys.schemas s ON o.schema_id = s.schema_id
WHERE
i.is_not_trusted = 1
AND i.is_not_for_replication = 0
AND i.is_disabled = 0
DB_NAME(),
s.name,
o.name,
i.name
sys.check_constraints i
INNER JOIN sys.schemas s ON o.schema_id = s.schema_id
WHERE
i.is_not_trusted = 1
Untrusted Foreign keys:
SELECT
DB_NAME(),
s.name,
o.name,
i.name
FROM sys.foreign_keys i
INNER JOIN sys.objects o ON i.parent_object_id = o.object_id
INNER JOIN sys.schemas s ON o.schema_id = s.schema_id
WHERE
i.is_not_trusted = 1
AND i.is_not_for_replication = 0
AND i.is_disabled = 0
s.name,
o.name,
i.name
INNER JOIN sys.schemas s ON o.schema_id = s.schema_id
WHERE
i.is_not_trusted = 1
Comments
Post a Comment