evidence

Sample T-SQL report: purge-audit-log.sql

A SQL Server maintenance script whose WHERE clause was commented out. The report shows what it changes, how far it reaches and whether it can be undone, with every finding tied to a rule ID and a line.

Synthetic sample. Not a real customer script. Every finding, the blast radius, coverage and reversibility are real engine output (ruleset 0.16.6). No AI explanation, rewrite or plans were added.

Verdict

Critical risk · Do not run as written

Changes: Deletes every row of dbo.AuditLog; Empties table dbo.AuditLogStaging; Changes database settings; DBCC ShrinkFile: shrinks database files.

Coverage
Fully analysed
Potential blast radius
Named container
Reversibility
Partial
Object count
Not checked: no expected count given
Runs as
The SQL Server login that runs the script (not determined from code)
Findings
2 critical1 high1 medium1 low

What this script does

What it says it does

Delete AuditLog rows older than 90 days on the SalesReporting database and keep everything newer

What the code actually does

Changes: Deletes every row of dbo.AuditLog; Empties table dbo.AuditLogStaging; Changes database settings; DBCC ShrinkFile: shrinks database files.

The intent text is not checked while the AI step is off; only the expected object count is compared with the blast radius.

Who and what it can reach

Named container. Every row of dbo.AuditLog

Irreversible operations

  • DELETE of every row of dbo.auditlog
  • TRUNCATE TABLE dbo.AuditLogStaging

SQL dialect: SQL Server T-SQL, as you chose; the detection agrees (signals: T-SQL: GO batch separator; T-SQL: @variable; T-SQL: GETDATE() / SYSDATETIME(); T-SQL: USE database).

  1. Take a backup of the database first, or copy the rows it changes with SELECT ... INTO a backup table.
  2. Run it inside BEGIN TRANSACTION, check the row counts, then COMMIT only if they match what you expect (otherwise ROLLBACK).
  3. Run it against a test copy of the database before production.

Findings5

What we found

DELETE on dbo.AuditLog reaches every row: no WHERE condition. Once committed, the rows can only be recovered from a backup.

Evidence · Line 9
9DELETE FROM dbo.AuditLog;

What to change

Add a WHERE condition that names exactly the rows to remove, check the count with a SELECT first, and run it in a transaction you can roll back.

Lower-risk pattern
1BEGIN TRAN; DELETE FROM <table> WHERE <key> = @value; -- check @@ROWCOUNT, then COMMIT or ROLLBACK
High confidenceSource: DeterministicDELETE (Transact-SQL) (opens in a new tab)

What we found

TRUNCATE TABLE removes every row of dbo.AuditLogStaging at once, with no WHERE condition and no row-by-row log. Outside a transaction that is rolled back, the rows can only be recovered from a backup.

Evidence · Line 12
12TRUNCATE TABLE dbo.AuditLogStaging;

What to change

Confirm the table is the one you mean (not a production table with a similar name) and copy the rows first.

Lower-risk pattern
1SELECT * INTO <schema>.<table>_backup_<date> FROM <schema>.<table>;
High confidenceSource: DeterministicTRUNCATE TABLE (Transact-SQL) (opens in a new tab)

What we found

The log chain is broken: point-in-time restore is impossible until a new full backup is taken, and log backups stop working. Nothing later in the script switches back.

Evidence · Line 17
17ALTER DATABASE SalesReporting SET RECOVERY SIMPLE;

What to change

Keep FULL recovery for databases that need point-in-time restore; take a full backup straight after switching back.

PermissionTypeStatusReason

Required SQL Server permissions are not assessed for T-SQL.

No rewrite was generated for this script.

  • Synthetic sample, not a real customer script. Every finding, the blast radius, coverage and reversibility are real engine output; no AI explanation, rewrite or plans were added.
  • T-SQL pack: SQL Server and Azure SQL syntax is parsed with Microsoft ScriptDom; no server is contacted, so row counts, object existence and permissions are not known.
  • Row reach is judged from the WHERE clause text only: a condition on a column that matches most rows is reported as filtered.
  • Procedures, functions and triggers not defined in the script are not analysed; sqlcmd :r includes are not analysed, and :!! shell commands only when they run powershell -Command.
  • Oracle, PostgreSQL and MySQL scripts are refused, not analysed.

Parser
0.1.0+scriptdom.180.140.0
PSScriptAnalyzer
not-enabled
Ruleset
0.16.6
Catalogue
0.3.0
Model
none
Schema
1.0.0
Completed
24 Nov 2026, 08:27 UTC

Report checksum is recorded server-side.

Run your own script.

No card required. Your script is never executed.