Does anyone know a query for listing out all foreign keys in a database with WITH NOCHECK description applied to it? (removing them will boost performance and
The following script will generate the alter statements that will both check existing data and prevent any new violations for foreign keys that are not currently trusted ('with nocheck').
Execute it in SQL Server Management Studio to generate the scripts and then copy them into a query window to execute them.
select
'alter table ' + quotename(s.name) + '.' + quotename(t.name) + ' with check check constraint ' + fk.name +';'
from
sys.foreign_keys fk
inner join
sys.tables t
on
fk.parent_object_id = t.object_id
inner join
sys.schemas s
on
t.schema_id = s.schema_id
where
fk.is_not_trusted = 1