From 49d3db4ddfb38416d43a77fdd39e5b88439ad24a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 15 Apr 2026 14:50:00 +0000 Subject: [PATCH 1/2] Initial plan From 9fad54c1550da5d8a282a67b4568b67e4e8326f2 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 15 Apr 2026 14:54:46 +0000 Subject: [PATCH 2/2] sp_Blitz: include foreign key count in untrusted FK warning details Agent-Logs-Url: https://github.com/BrentOzarULTD/SQL-Server-First-Responder-Kit/sessions/a0acda18-80c1-4d31-a268-7222355e50a9 Co-authored-by: BrentOzar <245462+BrentOzar@users.noreply.github.com> --- sp_Blitz.sql | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sp_Blitz.sql b/sp_Blitz.sql index 529de5ae..d56875fa 100644 --- a/sp_Blitz.sql +++ b/sp_Blitz.sql @@ -7403,16 +7403,17 @@ IF NOT EXISTS ( SELECT 1 Finding, URL, Details) - SELECT DISTINCT 48, + SELECT 48, N''?'', 150, ''Performance'', ''Foreign Keys Not Trusted'', ''https://www.brentozar.com/go/trust'', - (''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.'') + (''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.'') 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 AND ''?'' NOT IN (''gcloud_cloudsqladmin'', ''master'', ''model'', ''msdb'', ''rdsadmin'', ''ReportServer'', ''ReportServerTempDB'') + HAVING COUNT(*) > 0 OPTION (RECOMPILE);'; END;