commands

^

Get-DbaDbccStatistic

Author Patrick Flynn (@sqllensman)
Availability Windows, Linux, macOS

 

Want to see the source code for this command? Check out Get-DbaDbccStatistic on GitHub.
Want to see the Bill Of Health for this command? Check out Get-DbaDbccStatistic.

Synopsis

Execution of Database Console Command DBCC SHOW_STATISTICS

Description

Executes the command DBCC SHOW_STATISTICS against defined objects and returns results

Reclaims space from dropped variable-length columns in tables or indexed views

Read more:
- https://docs.microsoft.com/en-us/sql/t-sql/database-console-commands/dbcc-cleantable-transact-sql

Syntax

Get-DbaDbccStatistic
    [-SqlInstance] <DbaInstanceParameter[]>
    [[-SqlCredential] <PSCredential>]
    [[-Database] <String[]>]
    [[-Object] <String>]
    [[-Target] <String>]
    [[-Option] <String>]
    [-NoInformationalMessages]
    [-EnableException]
    [<CommonParameters>]

 

Examples

 

Example: 1
PS C:\> Get-DbaDbccStatistic -SqlInstance SQLServer2017

Will run the statement SHOW_STATISTICS WITH STAT_HEADER against all Statistics on all User Tables or views for every accessible database on instance SQLServer2017. Connects using Windows
Authentication.

Example: 2
PS C:\> Get-DbaDbccStatistic -SqlInstance SQLServer2017 -Database MyDb -Option DensityVector

Will run the statement SHOW_STATISTICS WITH DENSITY_VECTOR against all Statistics on all User Tables or views for database MyDb on instance SQLServer2017. Connects using Windows Authentication.

Example: 3
PS C:\> $cred = Get-Credential sqladmin
PS C:\> Get-DbaDbccStatistic -SqlInstance SQLServer2017 -SqlCredential $cred -Database MyDb -Object UserTable -Option Histogram

Will run the statement SHOW_STATISTICS WITH HISTOGRAM against all Statistics on table UserTable for database MyDb on instance SQLServer2017. Connects using sqladmin credential.

Example: 4
PS C:\> 'Sql1','Sql2/sqlexpress' | Get-DbaDbccStatistic -SqlInstance SQLServer2017 -Database MyDb -Object 'dbo.UserTable' -Target MyStatistic -Option StatsStream

Runs the statement SHOW_STATISTICS('dbo.UserTable', 'MyStatistic') WITH STATS_STREAM against database MyDb on instances Sql1 and Sql2/sqlexpress. Connects using Windows Authentication.

Required Parameters

-SqlInstance

The target SQL Server instance or instances.

Alias
Required True
Pipeline true (ByValue)
Default Value

Optional Parameters

-SqlCredential

Login to the target instance using alternative credentials. Accepts PowerShell credentials (Get-Credential).
Windows Authentication, SQL Server Authentication, Active Directory - Password, and Active Directory - Integrated are all supported.
For MFA support, please use Connect-DbaInstance.

Alias
Required False
Pipeline false
Default Value
-Database

The database(s) to process - this list is auto-populated from the server. If unspecified, all databases will be processed.

Alias
Required False
Pipeline false
Default Value
-Object

The table or indexed view for which to display statistics information.
Any two part object name should be formatted as 'Schema.ObjectName'

Alias
Required False
Pipeline false
Default Value
-Target

Name of the index, statistics, or column for which to display statistics information.
Target can be enclosed in brackets, single quotes, double quotes, or no quotes

Alias
Required False
Pipeline false
Default Value
-Option

Used to limit the result sets returned by the statement to the specified option.
Options are 'StatHeader', 'DensityVector', 'Histogram', 'StatsStream'
Default of StatHeader

Alias
Required False
Pipeline false
Default Value StatHeader
Accepted Values StatHeader,DensityVector,Histogram,StatsStream
-NoInformationalMessages

Suppresses all informational messages.

Alias
Required False
Pipeline false
Default Value False
-EnableException

By default, when something goes wrong we try to catch it, interpret it and give you a friendly warning message.
This avoids overwhelming you with "sea of red" exceptions, but is inconvenient because it basically disables advanced scripting.
Using this switch turns this "nice by default" feature off and enables you to catch exceptions with your own try/catch.

Alias
Required False
Pipeline false
Default Value False