/microsoft-sql-admin:investigate-statistics-issues [TopN] [ModificationThresholdPct] [StaleDaysThreshold] [MinRowsInTable] [MinExecutionCount] [IncludeViews] [DatabaseFilter]from Microsoft SQL administration
Investigates SQL Server statistics health across 20 diagnostic steps: staleness, histogram quality, plan cache impact, auto-update thresholds, and duplicates. Use when row estimates diverge from actual rows or statistics may be stale.
Ships in Microsoft SQL administration. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Investigates statistics health across 20 diagnostic steps: staleness, histogram quality, plan cache impact, index correlation, auto-update thresholds, duplicates, and more.
microsoft-sql-admin plugin (mssql_list_database_connections,
mssql_connect_database, then mssql_execute_query); any other SQL tool the agent host provides
for running T-SQL and reading result sets;
sqlcmd from a terminal. The
diagnostic queries are read-only; run UPDATE STATISTICS, CREATE/DROP STATISTICS, or ALTER DATABASE remediation only when the user asks for it. If the SQL Tools MCP server is not connected
or lists no connections, follow the sql-tools-mcp-setup skill, which asks before installing or
configuring anything. If no SQL tool can be made available, give the user the T-SQL to run and ask
for the results.SELECT @@SERVERNAME, DB_NAME(), SUSER_SNAME(), SERVERPROPERTY('EngineEdition')).Before starting, establish with the user:
MinRowsInTable and DatabaseFilter.| Parameter | Default | Description |
|---|---|---|
| TopN | 50 | Number of top results to return per step |
| ModificationThresholdPct | 10 | Percentage of rows modified to flag as stale |
| StaleDaysThreshold | 7 | Number of days since last update to flag as stale |
| MinRowsInTable | 1000 | Minimum rows in table to include in analysis |
| MinExecutionCount | 5 | Minimum plan execution count to flag plan cache issues |
| IncludeViews | 0 | Set to 1 to include indexed views in analysis |
| DatabaseFilter | NULL | Specific database name to analyze (NULL = current database). Note: This parameter is currently not implemented in the SQL queries. |
| EngineEdition | Platform | Key DMV Differences |
|---|---|---|
| 5 | Azure SQL Database | Single-database scope, no cross-database queries |
| 8 | Azure SQL Managed Instance | Instance-wide scope, most on-prem DMVs available |
| 12 | Fabric SQL Database | Behaves like Azure SQL Database (single-database scope) |
| 6, 11 | SQL Data Warehouse / Synapse | Not supported — statistics behavior differs significantly in DW |
| other | SQL Server on-prem / IaaS | Full DMV access including DBCC commands |
Execute all steps in order. Load and execute queries from references/queries.md — run the SQL exactly as written.
The workflow covers:
Load references/queries.md. Detects engine edition, SQL version, and capability flags. Save results for routing.
is_unsupported_dw = 1: Stop — skill does not apply to SQL DW / Synapse.engine_edition = 12 (Fabric): Behaves like Azure SQL Database — proceed with all steps.Load and execute queries from references/queries.md for Steps 2–8.
| Step | Focus | Key Output |
|---|---|---|
| 2 | Stale statistics (high modification count) | modification_percent > {{ModificationThresholdPct}} |
| 3 | Sampling and histogram quality | Sample rate, steps used, density anomalies |
| 4 | Statistics usage in plan cache | Staleness since compile, execution count impact |
| 5 | Index usage correlation | High-use indexes with stale stats, unused indexes |
| 6 | Auto-update threshold issues | Tables near or exceeding threshold |
| 7 | Column details and multi-column analysis | Leading column type, ascending key detection |
| 8 | Modification counter inventory | Version-compatible modification tracking |
Load and execute queries from references/queries.md for Steps 9–12.
| Step | Focus | Key Output |
|---|---|---|
| 9 | Incremental statistics detection | Partitioned tables without incremental stats |
| 10 | Statistics on computed columns | Computed column stats needing updates |
| 11 | Missing index correlation | Tables with stale stats AND missing indexes — high impact |
| 12 | Database-level settings audit | AUTO_CREATE/AUTO_UPDATE/ASYNC settings |
Load and execute queries from references/queries.md for Steps 13–20.
| Step | Focus | Key Output |
|---|---|---|
| 13 | Duplicate statistics | Redundant stats sharing leading columns |
| 14 | Empty histograms | Stats with 0 rows sampled — cause 1-row estimates |
| 15 | Statistics bloat | Tables with more stats objects than columns |
| 16 | Unused stale statistics | Auto-created stats with no seeks/scans |
| 17 | Orphaned DTA artifacts | Hypothetical indexes/stats left by Database Tuning Advisor |
| 18 | Missing multi-column FK statistics | Multi-column FKs without matching statistics |
| 19 | PERSIST_SAMPLE_PERCENT (SQL 2016 SP1+) | Fullscan stats that revert to default sampling |
| 20 | Fullscan-to-sample regression | Stats that were fullscanned but reverted to sampling |
Read references/report-template.md before presenting the final report.
modification_percent > 20%EngineEdition NOT IN (6, 11) — they will return an unsupported message on SQL DW / Synapse.sys.dm_db_stats_properties requires SQL 2008 R2 SP2+. On older versions, fall back to STATS_DATE().DBCC SHOW_STATISTICS is not available on Azure SQL DB (5), MI (8), or Fabric (12).STRING_AGG requires SQL 2017+. All queries use the STUFF/FOR XML PATH pattern for compatibility.sys.dm_exec_query_plan_stats requires SQL 2019+ with lightweight query profiling enabled.compatibility_level >= 130.PERSIST_SAMPLE_PERCENT requires SQL 2016 SP1+ (major version 13).What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub microsoft/microsoft-sql --plugin microsoft-sql-admin47 skills in this plugin
/active-connectionsUse when the user asks who is connected, which sessions are idle or hold the oldest open transaction, or how connections split by login or app. If a client can't connect, use `connectivity-troubleshoot`./always-encrypted-columnsUse when the user asks which plaintext columns can or should use Always Encrypted, or why a column is disqualified. Eligibility only: not for listing already-encrypted columns or their keys./authentication-diagnosticsUse when a login fails (18456, 'Login failed for user'), a user can't open a database, a permission is denied, or an Entra or managed identity login fails. For network errors, use `connectivity-troubleshoot`./backup-history-azuresqlUse when the user asks for backup history, the latest backups or backup retention on Azure SQL Database or Fabric SQL Database. For SQL Server or Managed Instance, use `backup-strategy-sqlserver`./backup-strategy-sqlserverUse when the user asks to review or design a SQL Server or Managed Instance backup strategy, or whether the recovery model and backup schedule meet an RPO. For Azure SQL Database, use `backup-history-azuresql`./blocking-root-cause-analysisUse when the user asks what caused blocking that already ended (yesterday's incident, intermittent lock waits) or who is behind a supplied blocking chain. For blocking happening now, use `check-live-blocking`.Other plugins' skills for the same job