SQL Server Backup Status Report: All Databases
Check SQL Server Backup Age Across All Databases This script queries the SQL Server backup history catalog to report the most recent full, differential, and transaction log backup for every database, including how many hours and minutes ago each backup completed. Purpose and Overview Database backups are your last line …
Read MoreA single catalog query can list every grant, deny, and role membership in a database, and the result is the starting point for an access review. The script below returns one flat result set that covers permissions granted directly to a user, permissions a user holds through a database role, and permissions granted to …
Read MoreSQL Server Search Stored Procedure and View Text
Apr 9, 2026 / · 10 min read · sql server sql scripts sys.sql_modules sys.objects stored procedures views database administration object search maintenance scripts schema management ·Before a column is renamed or a table is dropped, the question is which procedures, views, and functions still mention it. This script answers that by searching the stored text of every SQL module in the current database for a keyword, matching on the object name as well as the definition. It returns the schema, object …
Read MoreSQL Server Error Log Search Script: xp_readerrorlog
Apr 8, 2026 / · 9 min read · sql server sql scripts xp_readerrorlog sp_readerrorlog error log database administration monitoring diagnostics maintenance scripts sys.sp_enumerrorlogs ·A database goes suspect at 2 a.m., a backup job reports failure, or one login is being refused again and again, and the answer is a line in the SQL Server error log. This script finds that line from T-SQL: it filters by keyword, narrows by time window, reads archived logs and loads the result into a temp table for …
Read MoreSQL Server Script to Backup All Databases to Disk
Apr 8, 2026 / · 9 min read · sql server backup database maintenance sys.databases automation dba scripts full backup sql scripts maintenance scripts backup recovery ·An instance with thirty user databases needs thirty full backups, and writing thirty BACKUP DATABASE statements by hand means a new database is missed the day someone creates it. This T-SQL script reads sys.databases, selects every online user database and writes one compressed, checksummed full backup per database to …
Read MoreSQL Server Verify Backup Files: RESTORE VERIFYONLY
Verify SQL Server Backup Files with RESTORE VERIFYONLY Backup files that cannot be restored are worthless, and many DBAs discover problems only when they attempt an actual restore under pressure. The scripts in this article use RESTORE VERIFYONLY to confirm that backup files are readable and internally consistent …
Read MoreSQL Server Point-in-Time Restore with STOPAT
Apr 5, 2026 / · 8 min read · sql server restore backup recovery transaction log msdb database maintenance DBA scripts point in time restore sys.databases ·Recover a SQL Server Database to a Specific Point in Time SQL Server's RESTORE LOG ... WITH STOPAT lets you roll a database back to any exact moment covered by your backup chain. This guide walks through querying backup history in msdb, executing the restore sequence, and verifying the result. Purpose and Overview Data …
Read MoreSQL Server Top Queries by CPU and IO: dm_exec_query_stats
Find the Top CPU and IO Consuming Queries in SQL Server This script queries sys.dm_exec_query_stats to identify the most resource-intensive queries currently cached in the plan cache, showing logical reads, writes, CPU time, and elapsed time — with the full query text and execution plan for each. Purpose and Overview …
Read MoreSQL Server Index Fragmentation: dm_db_index_physical_stats
This T-SQL query lists the rowstore indexes in the current database whose leaf level is fragmented and large enough to be worth maintaining, and returns a ready-to-review ALTER INDEX statement for each one. It reads sys.dm_db_index_physical_stats in SAMPLED mode and filters on avg_fragmentation_in_percent and …
Read MoreSQL Server Database Size Report for All Databases
Which databases on this instance hold the most disk, and how large is each one in MB and GB? One query against sys.master_files and sys.databases answers that for every user database, sorted with the largest first. Purpose and Overview Capacity planning starts with a number per database: how much file space each one …
Read More