5 T-SQL Scripts Every DBA Should Have Ready Before 3 AM
Every senior DBA has been there. It's 3 AM, production is down, and you're scrambling through old scripts trying to find the right one.
Here are the 5 scripts I keep in my back pocket at all times:
1. Blocking Chain Detector
Forget sp_who2. You need a script that shows the full blocking chain ā head blocker, wait types, query text, and how long each session has been waiting. When the VP calls asking why the app is frozen, you need answers in 30 seconds.
2. Index Health Dashboard
One query that shows fragmentation, usage stats, missing indexes, and duplicate indexes across all databases. Run it weekly. Your future self will thank you.
3. Backup Verification Script
RESTORE VERIFYONLY is not enough. This script checks backup chain integrity, validates compression ratios against baselines, and flags any database that's overdue for a full backup.
4. Deadlock Analyzer
Pulls deadlock graphs from the system health extended event session, parses the XML, and gives you a clean table: victim process, winner process, resources involved, and the exact queries. No more digging through XML manually.
5. Space Forecaster
Tracks database growth rates over time and projects when you'll run out of disk. Gives you weeks of warning instead of a 3 AM page.
I've spent years refining these scripts in production environments managing 500+ databases. Inside SQLDBAVault, I share the actual scripts with full documentation, plus SOPs for every major DBA scenario.
Stop reinventing the wheel. Start with scripts that are already battle-tested.
