DBA Scripts: The Complete Guide

🔧Part of the DBA-Tools Project, copy/paste SQL Server scripts and health checks.

Where to Start With This Series

The DBA Scripts series on this blog covers backups, blocking, indexes, SQL Agent, query performance, extended events tracing, server inventory, and security, organized into eight areas of the job, each one tying together a cluster of scripts that answer a related set of questions. That’s a lot of ground, and “where do I actually start” is a fair question whether you’re new to this site or you’ve been inheriting an unfamiliar server every few months for years.

This post is the map above the maps: not a script itself, and not a pillar, but the guide to the pillars. It’s organized around the moments a DBA actually reaches for tooling, not around the categories the scripts happen to live in, so you can start from your actual situation rather than browsing a list.



Eight Areas of the Job

Start with the area that matches your situation, each one opens onto its focused hubs and the scripts underneath.

🗄️
Server & Configuration
What this server is and how it got that way: inventory, hardware, configuration, licensing, installation, and patching.
💽
Storage & Capacity
Disk, database, and filegroup free space, plus growth trend forecasting.
💾
Backup & Recovery
Coverage, integrity, encryption, and restore readiness.
🟢
High Availability
Always On, mirroring, failover clustering, and replication, across four technologies.
Performance & Troubleshooting
What’s actually slow and why: blocking, query tuning, live event tracing, and the collectors that baseline it all first.
🔐
Security
Who can do what, what’s actually happening at the login layer, and what’s missing entirely.
Maintenance & Automation
Scheduled jobs, index health, and generated maintenance DDL: what’s running and whether it’s still working.
🔁
Migration & Deployment
Logins, jobs, user mappings, linked servers, and restore-with-move DDL for a migration.

Start Here: Inheriting an Unfamiliar Server

If you’ve just been handed a server you’ve never seen before, this is the order that builds understanding fastest, each step assumes the last:

  1. Server Inventory first, always. Version, hardware, configuration, and licensing are the baseline everything else gets read against. Skipping this means every later finding is read without context.
  2. Backups and Recovery second. Before you touch anything or tune anything, confirm you could actually recover this server if something went wrong during the review itself.
  3. Security third, because the remediation it prompts is a change like any other. Who has privileged access, what’s actually happening at the login layer, and what auditing infrastructure does or doesn’t exist. This is the review most likely to surface something that changes your priorities for everything after it.
  4. Storage and Capacity fourth. Confirm there’s actually room to keep operating, disk, database, and filegroup free space, before anything else on this list.
  5. SQL Agent and Jobs fifth. What’s scheduled to run, whether it’s succeeding, and whether anything’s quietly getting slower. Maintenance jobs you didn’t know existed can explain a lot of otherwise-mysterious server behavior.
  6. Blocking and Locking, Index Maintenance, and Query and Performance Tuning last, once the foundation is confirmed sane, these three answer “is it fast enough and why not,” in whichever order matches the specific complaint you’re chasing.

By the Question You’re Actually Asking

Sometimes you don’t need the full review, you have one specific problem right now. Here’s the fast path for the moments that come up most.

“Is this server going to lose data?”
Backups and Recovery, specifically Backup Coverage and Suspect Pages and Integrity Checks
“Why is everything slow right now?”
Blocking and Locking first to rule out active blocking, then Query and Performance Tuning
“Did we just get compromised, or could we be?”
Security, start with Sysadmin Members and Login Security Audit
“A maintenance job silently stopped working, what else did?”
SQL Agent and Jobs
“We’re migrating or upgrading, what will break?”
Server Inventory, specifically Edition Feature Usage and Linked Servers
“I need to catch something live, the DMV snapshot already missed it”
Extended Events Tracing
“Queries feel slower than they used to, generally”
Index Maintenance, index health degrades quietly and this is the most commonly overlooked routine check
“Are we about to run out of room?”
Storage and Capacity, start with Database Free Space Summary and Database Growth Risk and Forecast
“Would a failover actually work right now?”
High Availability, start with AG Failover Readiness and Readable Secondary Usage

Jump Straight to a Popular Script

The most-reached-for scripts in the series, and the question each one answers:


Troubleshooting a Specific Error or Symptom

Not every question fits the pillar structure above. Some things are a specific error message or an active incident, not a survey of a whole area. A parallel Troubleshooting series covers those: step-by-step diagnostic workflows for a live problem, each one still linking back to the real scripts in the pillars above rather than duplicating them.

🔍 Got the exact error message? A searchable index of 47 errors in the SQL Server Errors Complete Guide, what each one means, and full write-ups for the common ones. Find your error →

Browse All Troubleshooting →


🖥️ The tool you’re running it all in SQL Server Management Studio: The Complete Guide The pillars above cover the server. SSMS gets its own complete guide because it’s the other half of the job: the client every one of these scripts gets pasted into. Setup, the settings that matter, and the habits that make script work faster. Open the SSMS guide →

Related script: Install and Update SSMS via PowerShell


What Makes This Series Different

Every script post follows the same shape on purpose: the real script, a genuine run against a live SQL Server instance with captured output, what a clean result looks like versus a real finding, and links to the scripts that answer the next logical question. Several posts exist because writing the explanation surfaced a real bug in the script itself, fixed and documented, not just described.

The standard: every script here has actually been run, not just written.

These scripts are also searchable by an AI assistant through the sqldba MCP server. Its find_script and get_script tools return the script body along with its safety class, so an assistant leads with the warning on anything that changes the server rather than handing over a command to paste.

Summary

Start with Server Inventory on any unfamiliar server, confirm Backups and Recovery before you touch anything, review Security next, then work outward toward the question that brought you here. For a specific error it’s the Troubleshooting series, for the tool itself the SSMS guide. Bookmark this page, and the pillar you land on next will link you the rest of the way.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *