SQL Server Kill Sessions: Filtered SPID Management
Apr 11, 2026 / · 9 min read · sql server session management kill spid database administration dm exec sessions maintenance scripts sql scripts database connections active sessions open transactions ·Kill 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 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 ·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 Blocking Detection: Find Blocked Sessions
Mar 1, 2026 / · 5 min read · sql server blocking performance dm exec requests dm exec sessions wait types dba scripts monitoring query tuning ·Blocking in SQL Server occurs when one session holds a lock that another session needs, causing the second session to wait. This T-SQL script queries the dynamic management views to show all currently blocked sessions, the blocking session, wait type, wait duration, and the SQL text involved. Purpose and Overview When …
Read MoreSQL Server Missing Indexes Report: dm_db_missing_index
Feb 28, 2026 / · 6 min read · sql server missing indexes performance dm db missing index details dm db missing index group stats index tuning dba scripts query optimization ·SQL Server tracks index recommendations automatically as queries execute, storing them in the missing index DMVs. This T-SQL script queries those views to produce a ranked report of missing indexes, ordered by the estimated improvement they would provide, along with a ready-to-run CREATE INDEX statement for each …
Read MoreSQL Server Wait Statistics Report: dm_os_wait_stats
Feb 27, 2026 / · 6 min read · sql server wait statistics performance dm os wait stats wait types bottleneck analysis dba scripts performance tuning ·Wait statistics are one of the most reliable ways to identify performance bottlenecks in SQL Server. This T-SQL script queries sys.dm_os_wait_stats, filters out background and idle wait types that do not indicate real problems, and ranks the remaining waits by their percentage of total wait time. Purpose and Overview …
Read MoreSQL Server Primary Key Discovery Script: sp_pkeys Guide
Aug 9, 2025 / · 3 min read · sql server primary keys database administration scripts sysobjects sp_pkeys dynamic sql sysobjects sys.tables sys.key_constraints INFORMATION_SCHEMA.TABLE_CONSTRAINTS ·SQL Server Primary Key Discovery Script Using sp_pkeys and sysobjects Purpose This SQL Server script generates dynamic SQL statements that can be executed to discover primary keys across all user tables in a database. It's a powerful administrative tool that helps database administrators quickly identify primary key …
Read MoreSQL Server: Find Tables with Clustered Indexes for Rebuild
SQL Server Query to Identify Tables with Clustered Indexes for Rebuilding Database administrators frequently need to perform maintenance operations on clustered indexes to optimize database performance. This SQL Server query provides a quick and efficient way to identify all user tables that contain clustered indexes, …
Read MoreSQL Server Object Permissions: Generate GRANT Statements
Aug 8, 2025 / · 5 min read · sql server database security permissions grant statements database administration sql scripts security database objects sysobjects ·SQL Server Object-Level Permissions Script: Generate GRANT Statements for Database Security Database security is a critical aspect of SQL Server administration, and managing permissions at the object level can be time-consuming when done manually. This SQL Server script automates the process of generating GRANT …
Read More