Check AG Replica Health with sys.dm_hadr_availability_replica_states
Sep 13, 2026 / · 9 min read · sql server sys.dm_hadr_availability_replica_states sys.dm_hadr_availability_group_states sys.availability_replicas sys.availability_groups sys.dm_hadr_database_replica_cluster_states sys.dm_hadr_database_replica_states always on synchronization health failover readiness scripts ·An Always On availability group can show green across every tile in the graphical dashboard and still be one dropped connection away from a failover nobody planned for. sys.dm_hadr_availability_replica_states is the dynamic management view behind that dashboard tile, returning role, operational state, and …
Read MoreAudit Server Configuration Drift with sys.configurations
Aug 24, 2026 / · 8 min read · sql server sys.configurations sp_configure reconfigure configuration drift advanced options xp_cmdshell security monitoring scripts ·Running sp_configure and getting back a success message is not the same thing as a setting actually taking effect. Between the moment a value is changed and the moment SQL Server is actually running it sits a gap — one a busy DBA can close with a single RECONFIGURE, or forget entirely until a restart months later flips …
Read MoreConfigure Database Mail and Send a Test Message
Jul 1, 2026 / · 12 min read · sql server database mail sp_send_dbmail sysmail_add_account_sp sysmail_event_log msdb sql server agent sys.configurations sys.databases sysmail_allitems administration scripts ·Database Mail is switched off on a new instance, and sp_send_dbmail cannot work until an SMTP account, a profile that holds it, and a grant that lets users send through that profile all exist in msdb. The script below enables the feature, builds those three objects, sends a test message, and reads the queue and the …
Read MoreList All Tables Across All Databases in SQL Server
Jun 29, 2026 / · 9 min read · sql server sys.databases sys.tables sys.schemas sys.partitions dynamic sql cross database catalog views table inventory sp_executesql administration metadata scripts ·A table inventory that spans every database on an instance cannot be answered from one database context, because the table catalog lives inside each database. The pattern below reads the database list from sys.databases, builds one INSERT ... SELECT per online user database against that database's sys.tables and …
Read MoreSQL Server DBCC CHECKIDENT: Check and Reseed Identity
A logging table grew to forty million rows, the bulk of it was archived out, and now only the last week's data remains — but the next insert still gets identity value 40,000,001, leaving a vast gap below it. Or a botched data load left the seed sitting far above the real maximum, and future inserts skip millions of …
Read MoreSQL Server Object Dependencies Report: Find All References
Before renaming a column, retiring a view, or dropping a stored procedure, every DBA needs the answer to one question: what else depends on this object? This T-SQL script reads sys.sql_expression_dependencies and reports every referencing-and-referenced pair in the current database, with optional filtering to a single …
Read MoreSQL Server Max Server Memory Calculator Script
Every SQL Server installation ships with max server memory set to its default value of 2,147,483,647 MB — effectively unlimited — which allows the Buffer Pool to consume all available RAM and starve the operating system of the memory it needs for network stack, disk I/O, and other critical processes. This script reads …
Read MoreSQL Server MAXDOP Recommendation Script
Apr 17, 2026 / · 8 min read · sql server maxdop performance sp_configure numa sql scripts database administration cpu configuration sys.configurations sys.dm_os_schedulers sys.dm_os_sys_info ·MAXDOP (max degree of parallelism) caps how many processors SQL Server uses for a single parallel query plan. The default value of 0 lets SQL Server use all available processors, up to 64, which Microsoft says is not the recommended value for most cases. This script reads the CPU and NUMA layout from system DMVs, …
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 sys.server_principals ·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 for each status (failed, succeeded, and so on), failure and success counts over the last 60 days, total lifetime run counts, and job step …
Read MoreThis T-SQL script kills one or more SQL Server sessions (SPIDs) chosen by filters: login, database, session state, open transactions and the age of the last request. It reads sys.dm_exec_sessions, builds a KILL statement for each match, and by default only prints what it would do. Purpose and Overview Clearing …
Read More