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).
- Take a backup of the database first, or copy the rows it changes with SELECT ... INTO a backup table.
- Run it inside BEGIN TRANSACTION, check the row counts, then COMMIT only if they match what you expect (otherwise ROLLBACK).
- 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.
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.
1BEGIN TRAN; DELETE FROM <table> WHERE <key> = @value; -- check @@ROWCOUNT, then COMMIT or ROLLBACK
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.
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.
1SELECT * INTO <schema>.<table>_backup_<date> FROM <schema>.<table>;
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.
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.
| Permission | Type | Status | Reason |
|---|
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.