Read-only T-SQL diagnostics for SQL Server backups, database and file capacity, index fragmentation, and statistics maintenance.
| Script | Scope | Purpose |
|---|---|---|
backup_health.sql |
Instance + msdb |
Reviews the latest non-copy-only full, differential, and log backups. |
database_sizes.sql |
Current database | Reports allocated file size, data-file free space, log use, maximum size, and autogrowth. |
file_space.sql |
Current database | Highlights low data-file free space and percentage or small fixed autogrowth. |
fragmentation.sql |
Current database | Finds fragmented rowstore indexes and generates REORGANIZE or REBUILD candidates. |
statistics.sql |
Current database | Finds uninitialized or highly modified statistics and generates update commands. |
- Use
backup_health.sqlas a history check, then validate jobs, media, retention, encryption, and restore tests. - Use
database_sizes.sqlfor the fuller file/log report; usefile_space.sqlfor a compact capacity and growth review. - Correlate
fragmentation.sqlwith workload, page count, page density, storage behavior, and maintenance windows. - Correlate
statistics.sqlwith query regressions and cardinality estimates; age alone does not make statistics stale.
msdbhistory can be absent, purged, or bypassed by some third-party/VSS tooling. Backup history is not proof of recoverability.file_space.sqlcalculates used/free space for data files; usedatabase_sizes.sqlfor database-wide transaction-log utilization.- Generated
ALTER INDEX,UPDATE STATISTICS, and file-growth statements are returned as text only. - Index rebuilds and statistics updates can consume CPU, I/O, TempDB, log space, and blocking time.
- Azure SQL manages backups and files differently; check the platform notes before use.
Review the compatibility guide and each script header before production use.