Skip to content

Commit 9fad54c

Browse files
CopilotBrentOzar
andauthored
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>
1 parent 49d3db4 commit 9fad54c

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
@@ -7403,16 +7403,17 @@ IF NOT EXISTS ( SELECT 1
74037403
Finding,
74047404
URL,
74057405
Details)
7406-
SELECT DISTINCT 48,
7406+
SELECT 48,
74077407
N''?'',
74087408
150,
74097409
''Performance'',
74107410
''Foreign Keys Not Trusted'',
74117411
''https://www.brentozar.com/go/trust'',
7412-
(''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.'')
7412+
(''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.'')
74137413
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
74147414
WHERE i.is_not_trusted = 1 AND i.is_not_for_replication = 0 AND i.is_disabled = 0 AND ''?''
74157415
NOT IN (''gcloud_cloudsqladmin'', ''master'', ''model'', ''msdb'', ''rdsadmin'', ''ReportServer'', ''ReportServerTempDB'')
7416+
HAVING COUNT(*) > 0
74167417
OPTION (RECOMPILE);';
74177418
END;
74187419

0 commit comments

Comments
 (0)