SQL Server Backup History: Duration and Size Report
Apr 13, 2026 / · 6 min read · sql server backup recovery msdb sql scripts database administration backup monitoring maintenance scripts reporting sys.databases backupset ·Query Backup Duration and File Size from SQL Server History This script queries SQL Server's msdb backup history to report the backup type, start and finish time, duration in minutes, and file size in both megabytes and gigabytes for every backup across all user databases on the server. Purpose and Overview Knowing …
Read MoreSQL Server Long-Running Queries: Find Active Sessions
Apr 12, 2026 · 6 min read · sql server performance monitoring sql scripts sys.dm_exec_requests sys.dm_exec_sql_text blocking wait types database administration active sessions ·Find Active Long-Running Queries in SQL Server This script queries sys.dm_exec_requests and sys.dm_exec_sql_text to show all currently executing queries on the SQL Server instance, sorted by how long they have been running, along with CPU time, I/O activity, blocking status, and wait type information. Purpose and …
Read MoreSQL Server Agent Job Failure History Report
Apr 11, 2026 / · 8 min read · sql server sql server agent msdb sql scripts database administration job monitoring maintenance scripts reporting sysjobs sysjobhistory ·Report SQL Server Agent Job Status and Failure History This script queries the SQL Server Agent job history stored in msdb to produce a detailed report of each job's most recent run status, failure and success counts over the last 60 days, total lifetime run counts, and job step information including subsystem type and …
Read MoreKill SQL Server Sessions with Targeted Filters Using KILL and dm_exec_sessions This article covers a practical T-SQL script that kills one or more SQL Server sessions (SPIDs) while giving you precise control over which sessions are targeted. The script uses sys.dm_exec_sessions to query active sessions and a cursor to …
Read MoreSQL 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 MoreSQL Server User Permissions and Role Memberships
Audit SQL Server Database User Permissions and Role Memberships This script queries the SQL Server system catalog to produce a complete audit of database-level permissions, covering direct object grants to users, permissions inherited through database roles, and permissions granted to the public role — all in a single …
Read MoreSQL Server Search Stored Procedure and View Text
Apr 9, 2026 / · 6 min read · sql server sql scripts sys.sql_modules sys.objects stored procedures views database administration object search maintenance scripts schema management ·Search Stored Procedure and View Definitions in SQL Server This script searches the text of stored procedures, views, functions, and triggers in the current database using sys.sql_modules, returning any programmable object whose name or definition contains a given keyword. Purpose and Overview Finding which stored …
Read MoreSQL Server Error Log Search Script: xp_readerrorlog
Apr 8, 2026 / · 7 min read · sql server sql scripts xp_readerrorlog sp_readerrorlog error log database administration monitoring diagnostics maintenance scripts sys.sp_enumerrorlogs ·Search the SQL Server Error Log with xp_readerrorlog This script reads and filters the SQL Server error log using xp_readerrorlog and sys.sp_readerrorlog, supporting keyword search, date range filtering, and access to archived log files — all from T-SQL without touching the file system. Purpose and Overview The SQL …
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 More