T-SQL diagnostics for foreign-key indexing, constraint state, trust, and orphaned data. These scripts report evidence and do not repair user data automatically.
| Script | Cost | Purpose |
|---|---|---|
fk_analysis.sql |
Low | Finds foreign keys without a supporting index and reports disabled or untrusted keys. |
orphaned_records.sql |
Potentially high | Scans every user foreign-key relationship for child rows without a matching parent. |
untrusted_constraints.sql |
Low | Reports disabled or untrusted foreign-key and check constraints with validation SQL. |
- Run
fk_analysis.sqlto inspect foreign-key support and state. - Run
untrusted_constraints.sqlto identify constraints the optimizer cannot trust. - Run
orphaned_records.sqlin a controlled window when validation is required. - Investigate application rules, replication behavior, loading processes, and historical data fixes.
- Correct data only through an approved, tested remediation plan.
- Re-enable and validate constraints only after confirming existing rows satisfy them.
- A foreign key does not always need its own index; consider table size, workload, column order, and existing indexes.
- An untrusted constraint can be enabled while still not trusted. Validation may scan and lock large tables.
orphaned_records.sqluses quoted dynamic object names and read-onlyCOUNT_BIGqueries, but can perform substantial I/O.- Never delete orphaned rows automatically. The correct action may be restoring parent data, correcting child data, or documenting an intentional exception.
Review the compatibility guide and each script header before production use.