SQL Server DBA Scripts & Tools

dba-tools is the toolkit I use as a working SQL Server DBA, free and open on GitHub. Copy/paste scripts for the day-to-day, a one-command health check, and an AI assessment that reviews the whole server with you.

📋 Copy/Paste First

170+ production-safe SQL scripts. Open one, paste it into SSMS, run it. No install, no parameters, no magic variables.

🩺 Health Check

39 diagnostic scripts run in a single command, saved as CSVs, then a rules review flags CRITICAL / WARNING / INFO findings.

🤖 AI Assessment

The flagship. An AI reads the whole collection, correlates findings into root causes, and writes a prioritized report.

Quick Start

Clone the repo and run the setup script. It checks prerequisites, installs the SqlServer module if missing, and verifies the connection. Pass or fail, it tells you exactly what to do next.

git clone https://github.com/peterwhyte-lgtm/dba-tools
cd dba-tools
.\Initialize-Environment.ps1

To target a remote or named instance instead:

.\Initialize-Environment.ps1 -ServerInstance PROD01\SQL2025

Once setup passes, the server is saved for the session and every script picks it up automatically. Everything is read-only by default, and every script header states the permissions it needs and what it touches.

🤖 The Health Check, Reviewed by AI

The flagship workflow. A collection runs 39 diagnostic scripts against an instance (backups, waits, blocking, memory, disk, security surface area) and saves every result as a CSV. A rules review turns those into deterministic findings. Then the AI assessment reads the whole collection and does what fixed thresholds can’t: it correlates findings across the outputs into root causes and writes a prioritized report with evidence and a fix for each issue.

It’s a second reviewer that has read every output, doesn’t get tired, and surfaces the blindspots you’d miss at 2am. Nothing is sent to any AI until you run the assessment step yourself.

Three commands take a server from no idea to a written assessment:

# 1. Collect
.\powershell\reporting\Invoke-HealthCheckCollection.ps1 -ServerInstance PROD01\SQL2025
# 2. Rules review
.\powershell\reporting\Review-HealthCheckOutput.ps1
# 3. AI assessment
.\powershell\reporting\Invoke-AiAssessment.ps1

What’s Inside

⚡ Performance & Troubleshooting
Blocking, long-running queries, wait stats, missing indexes, deadlocks.

📊 Monitoring & Health
CPU, memory, disk pressure, TempDB, SQL Agent jobs, configuration checks.

💾 Backups & Recovery
Backup coverage, history, restore validation, gap detection.

🔐 Security & Configuration
Logins, permissions, sysadmin review, orphaned users.

🟢 High Availability
Always On health, replica state, sync latency.

🚚 Migration Support
Compatibility checks, deprecated features, DDL generators for logins, jobs and users.

Three Ways to Run It

1. SQL in SSMS

Copy any script from the repo straight into SSMS, run it, and get results immediately. This is the core toolkit path and needs nothing else installed.

2. PowerShell

Run the same scripts by name from terminal, for example .\run.ps1 Get-WaitStatistics, and export output to CSV for analysis and reporting.

3. The Web UI

A local dashboard where collections are viewed and verified: health scorecard, security drill-down, disk capacity, AI reports, and live incident triage.

Script Articles

The scripts worth explaining get their own articles: what the script returns, when to use it, and the full script ready to copy. Good starting points, grouped by the job in hand:

Production DBA Daily Scripts

Day-to-day production shortlist. These are the scripts to grab first when triaging activity, checking capacity, validating resilience, and getting through change windows safely.

Grab the Toolkit

Free and open source. Every script came from a real situation: an incident, a migration window, or a routine check that needed to be fast and safe.