Get-sqmStatisticsHealth
Performance
sqmSQLTool v1.9.196+ · Diagnostics
NeedsUpdate: changes since the last update reach MIN(SQRT(1000 x rows), rows x 10 %), or at least one change and older than 30 days.Per statistic: rows, sampled rows and sample percent, histogram steps, modifications, threshold, last update and age, NORECOMPUTE, persisted sample, filter, and a status:
• Ok, Stale (update due), NeverUpdated (no data, skipped by Invoke-sqmUpdateStatistics), NoRecompute (changes, but SQL Server never updates it automatically)
Every row also carries the database settings AUTO_UPDATE_STATISTICS, its ASYNC variant and AUTO_CREATE_STATISTICS, so a database with auto update off shows up directly.
Execution Flow
Parameters
| Parameter | Type | Required | Default | Notes |
|---|---|---|---|---|
| -SqlInstance | string | Optional | $env:COMPUTERNAME | Target SQL Server instance. |
| -SqlCredential | PSCredential | Optional | , | Credentials for the connection. |
| -Database | string | Optional | * = all user DBs | Database name or wildcard pattern. System databases only when named explicitly. |
| -Table | string | Optional | * | Table name or wildcard pattern. |
| -Statistics | string | Optional | * | Statistic name or wildcard pattern. |
| -ModificationThreshold | Dynamic | Any | Optional | Dynamic | Dynamic: MIN(SQRT(1000 x rows), rows x percent / 100). Any: at least one change. |
| -ModificationPercent | int | Optional | 10 | Percentage part of the dynamic threshold. |
| -MaxAgeDays | int | Optional | 30 | With at least one change and older than this, a statistic counts as stale. 0 = off. |
| -Index | bool | Optional | $true | $false: column statistics only. |
| -OnlyProblems | switch | Optional | $false | Only Stale, NeverUpdated and NoRecompute statistics with changes. |
| -Summary | switch | Optional | $false | One row per database instead of one row per statistic. |
| -OutputPath | string | Optional | <OutputPath config>\StatisticsHealth | Directory for CSV + HTML report. Pass an empty string to skip the files. |
| -NoOpen | switch | Optional | $false | Do not open the HTML report after creation. |
| -EnableException | switch | Optional | $false | Throw exceptions immediately instead of logging and continuing. |
Examples
What would the next statistics run update?
Get-sqmStatisticsHealth -SqlInstance 'SQL01' -OnlyProblems -OutputPath '' |
Format-Table Database, Table, Statistic, Rows, Modifications, AgeDays, Reason
One line per database, including the auto-update settings
Get-sqmStatisticsHealth -SqlInstance 'SQL01' -Summary -OutputPath ''