SQL Server DBA Scripts
Copy and paste scripts from the toolkit I use as a working SQL Server DBA, free and open source as dba-tools. Every script link lands on the code.
New here? Start with the Complete Guide
Go-To Scripts
The ones I reach for first. Each link lands on the script, ready to copy.
The Script Areas
Each area in its colour, with its pillars and the scripts to start with. See how it all connects on the Site Map.
Server & Configuration
What this server is, and how it’s installed and patched.
Pillars: Server Inventory, SQL Server Installation
Start with: Patch Level, Config Score, OS and Hardware Info, Configuration Snapshot
Storage & Capacity
Disk, database and filegroup free space, plus growth forecasting.
Start with: Disk Space, Free Space Summary, Database Sizes, Growth Events, Growth Forecast
Backup & Recovery
Coverage, integrity, encryption, and restore readiness.
Start with: Backup Coverage, Backup and Restore Progress, Restore Time Estimate, Restore History, Backup Chain Integrity
High Availability
Always On, mirroring, failover clustering, and replication.
Start with: AG Latency, AG Replica State, AG Failover Readiness, Replication Status, Log Shipping Status
Performance & Troubleshooting
Blocking, deadlocks, wait stats, missing indexes, live tracing.
Pillars: Query, Blocking and Locking, Extended Events Tracing, Collectors
Start with: Active Sessions, Blocking Chains, Wait Statistics, Missing Indexes, Top CPU Queries
Security
Logins, permissions, sysadmin review, orphaned users.
Start with: Login Permissions, Permissions and Role Membership, Sysadmin Members, Certificates and TDE, Fix Orphaned Users
Maintenance & Automation
SQL Agent jobs, index maintenance, generated maintenance jobs.
Pillars: SQL Agent and Jobs, Index Maintenance, SQL Server Maintenance Job Framework
Start with: Index Fragmentation, Agent Job Failures, Maintenance Job Status, SQL Agent Job Overview
Migration & Deployment
Compatibility checks, deprecated features, DDL generators.
Pillar: SQL Server Migration Script Generators
Start with: Migration Risk, Orphaned Users, Fix Orphaned Users
How Deep Do You Need to Go?
Stopping at the first one is a perfectly good answer.
Copy/Paste First
195 SQL scripts, 182 of them read-only, documented across 130 pages here. Open one, paste it into SSMS, run it. No install, no parameters, no magic variables.
Health Check
45 diagnostic scripts run in a single command, saved as CSVs, then a rules review flags CRITICAL / WARNING / INFO findings.
AI Assessment
An AI reads the whole collection, correlates findings into root causes, and writes a prioritized report.
Clone it, run one command
Setup, for the second and thirdA single script needs nothing installed. The collection and the assessment run from the repo, and that is the whole of it. Read-only by default, and every script header states the permissions it needs and what it touches.
git clone https://github.com/peterwhyte-lgtm/dba-tools
cd dba-tools
.\Initialize-Environment.ps1
🤖 The Health Check, Reviewed by AI
The flagship workflow. A collection runs 45 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.
Nothing is sent to any AI until you run the assessment step yourself. See a real assessment, end to end →
A 30-second run: terminal command, web UI output, then the same script in SSMS.
Where You Run It
Copy and paste it
Take a script from the post that explains it, or from the repo, and paste it into SSMS. Self-contained and read-only, so it runs as-is.
Needs any query window
Run it from the repo
Clone the toolkit and call scripts by name. Output lands as CSV you can keep and compare, across as many servers as you like.
Needs PowerShell
Start the Web UI
Launch the local dashboard and work from it: health scorecard, drill-downs, AI reports and incident triage. Runs entirely on your machine.
Needs PowerShell, then a browser
Whichever route you pick, most of this ends up in SQL Server Management Studio. If yours is out of date, missing something you expected, or was never set up the way a DBA wants it, the SSMS complete guide covers installing and updating it, the settings worth changing, and the shortcuts that save real time.
Give your AI assistant the same reference, as tools it can call
The assessment above hands an AI one server’s output. The sqldba MCP server hands it the whole library instead: every error write-up, wait type, build and support date, and all 244 scripts with the safety class on each one. Your assistant looks the answer up and cites the page rather than recalling it.
Free, MIT licensed, runs locally, and it has no database connection at all.
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.
Script Finder
Every script on the site, searchable. Type what is actually going wrong, or filter by area.
What do you need right now?
Showing all 130 scripts
- Site Map, how the pillars, areas and scripts connect
- DBA Quick Links, the scripts reached for most, with a filter
- The Complete Guide, how the scripts are organised and how to pick between them