Skip to content

Commit b4e3cef

Browse files
authored
Merge pull request BrentOzarULTD#3912 from BrentOzarULTD/copilot/add-foreign-keys-count-to-warning
sp_Blitz: include affected foreign key count in “Foreign Keys Not Trusted” details
2 parents 782540e + 9fad54c commit b4e3cef

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

sp_Blitz.sql

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7399,16 +7399,17 @@ IF NOT EXISTS ( SELECT 1
73997399
Finding,
74007400
URL,
74017401
Details)
7402-
SELECT DISTINCT 48,
7402+
SELECT 48,
74037403
N''?'',
74047404
150,
74057405
''Performance'',
74067406
''Foreign Keys Not Trusted'',
74077407
''https://www.brentozar.com/go/trust'',
7408-
(''The ['' + DB_NAME() + ''] database has foreign keys that were probably disabled, data was changed, and then the key was enabled again. Simply enabling the key is not enough for the optimizer to use this key - we have to alter the table using the WITH CHECK CHECK CONSTRAINT parameter.'')
7408+
(''The ['' + DB_NAME() + ''] database has '' + CAST(COUNT(*) AS NVARCHAR(20)) + '' foreign keys that were probably disabled, data was changed, and then the key was enabled again. Simply enabling the key is not enough for the optimizer to use this key - we have to alter the table using the WITH CHECK CHECK CONSTRAINT parameter.'')
74097409
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
74107410
WHERE i.is_not_trusted = 1 AND i.is_not_for_replication = 0 AND i.is_disabled = 0 AND ''?''
74117411
NOT IN (''gcloud_cloudsqladmin'', ''master'', ''model'', ''msdb'', ''rdsadmin'', ''ReportServer'', ''ReportServerTempDB'')
7412+
HAVING COUNT(*) > 0
74127413
OPTION (RECOMPILE);';
74137414
END;
74147415

0 commit comments

Comments
 (0)