Seen on a customer's SQL Server 2005 SP4 (legacy ODBC): - agent-jobs declared @since with an initial value (2008+): "Incorrect syntax near CONVERT" and SQLI-JOB-001/002 never ran. Now DECLARE; SET. - plan-analysis used query_hash (2008+) and failed every 30 minutes for SQLI-PLAN-001/002/003. On 2005 a statement is now identified by sql_handle + offsets, as top SQL does. It needs sys.dm_exec_text_query_plan, so the new capability TextQueryPlan (2005 SP2, 9.0.3042) is required. - COM-DB-001 used OBJECT_SCHEMA_NAME (2005 SP2+); now joins sys.objects and sys.schemas. Audit of all collector SQL and community rules without minimumVersion 10.0: the rest is 2005 syntax or behind a version/capability check. Sql2005CompatibilityTests (2005 cannot run in CI): every collector that can run on 2005 is scanned for 2008+ syntax in its SQL (inline DECLARE, +=, MERGE, CONCAT/IIF/FORMAT/TRY_*, OFFSET/FETCH, date/time types, multi-row VALUES), version-branched files listed explicitly; the same for community rules; and the 2005 variants of plan analysis and top SQL must not use query_hash. Verified to fail on the old agent-jobs SQL. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
19 lines
1.4 KiB
JSON
19 lines
1.4 KiB
JSON
[
|
|
{
|
|
// Example of a database-scoped rule: the query runs in every online user database, and the column
|
|
// "database" is added to each row automatically.
|
|
"id": "COM-DB-001",
|
|
"title": "Fremmednøgler, som SQL Server ikke stoler på",
|
|
"severity": "Low",
|
|
"scope": "Database",
|
|
"query": "SELECT s.name + '.' + o.name AS [table], fk.name AS [constraint] FROM sys.foreign_keys fk JOIN sys.objects o ON o.object_id = fk.parent_object_id JOIN sys.schemas s ON s.schema_id = o.schema_id WHERE fk.is_not_trusted = 1 AND fk.is_disabled = 0",
|
|
"subject": "constraint: {database}/{constraint}",
|
|
"findingTitle": "{database}: fremmednøglen {constraint} på {table} er ikke betroet",
|
|
"explanation": "Nøglen er blevet slået til igen uden WITH CHECK, fx efter en dataindlæsning. Den håndhæves for nye rækker, men SQL Server kan ikke stole på eksisterende data, så optimizeren udnytter den ikke til at fjerne joins, og der kan ligge ugyldige data.",
|
|
"recommendation": "Kontrollér og betro nøglen: ALTER TABLE {table} WITH CHECK CHECK CONSTRAINT [{constraint}]; Fejler det, findes der rækker, som bryder nøglen, og de skal rettes først. Kør det uden for spidsbelastning på store tabeller.",
|
|
"references": [
|
|
{ "title": "ALTER TABLE ... WITH CHECK", "url": "https://learn.microsoft.com/sql/t-sql/statements/alter-table-transact-sql" }
|
|
],
|
|
"author": "SQLInsight Pro"
|
|
}
|
|
]
|