< Back
Get-DbaDbccStatistic
Post
NAME Get-DbaDbccStatistic
SYNOPSIS
Execution of Database Console Command DBCC SHOW_STATISTICS
SYNTAX
Get-DbaDbccStatistic [-SqlInstance] <Sqlcollaborative.Dbatools.Parameter.DbaInstanceParameter[]> [[-SqlCredential]
<Pscredential>] [[-Database] <System.String[]>] [[-Object] <String>] [[-Target] <String>] [[-Option] <String>]
[-NoInformationalMessages <Switch>] [-EnableException <Switch>] [<CommonParameters>]
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- ... ansact-sql
PARAMETERS
-Database [<System.String[]>]
The database(s) to process - this list is auto-populated from the server. If unspecified, all databases will
be processed.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-EnableException [<Switch>]
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.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-NoInformationalMessages [<Switch>]
Suppresses all informational messages.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-Object [<String>]
The table or indexed view for which to display statistics information.
Any two part object name should be formatted as 'Schema.ObjectName'
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-Option [<String>]
Used to limit the result sets returned by the statement to the specified option.
Options are 'StatHeader', 'DensityVector', 'Histogram', 'StatsStream'
Default of StatHeader
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-SqlCredential [<Pscredential>]
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.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-SqlInstance [<Sqlcollaborative.Dbatools.Parameter.DbaInstanceParameter[]>]
The target SQL Server instance or instances.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-Target [<String>]
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
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
<CommonParameters>
This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer, PipelineVariable, and OutVariable. For more information, see
about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).
INPUTS
OUTPUTS
NOTES
Tags: DBCC, Statistics
Author: Patrick Flynn (@sqllensman)
Website: https://dbatools.io
Copyright: (c) 2018 by dbatools, licensed under MIT
License: MIT https://opensource.org/licenses/MIT
-------------------------- 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.
RELATED LINKS
https://dbatools.io/Get-DbaDbccStatistic
SYNOPSIS
Execution of Database Console Command DBCC SHOW_STATISTICS
SYNTAX
Get-DbaDbccStatistic [-SqlInstance] <Sqlcollaborative.Dbatools.Parameter.DbaInstanceParameter[]> [[-SqlCredential]
<Pscredential>] [[-Database] <System.String[]>] [[-Object] <String>] [[-Target] <String>] [[-Option] <String>]
[-NoInformationalMessages <Switch>] [-EnableException <Switch>] [<CommonParameters>]
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- ... ansact-sql
PARAMETERS
-Database [<System.String[]>]
The database(s) to process - this list is auto-populated from the server. If unspecified, all databases will
be processed.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-EnableException [<Switch>]
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.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-NoInformationalMessages [<Switch>]
Suppresses all informational messages.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-Object [<String>]
The table or indexed view for which to display statistics information.
Any two part object name should be formatted as 'Schema.ObjectName'
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-Option [<String>]
Used to limit the result sets returned by the statement to the specified option.
Options are 'StatHeader', 'DensityVector', 'Histogram', 'StatsStream'
Default of StatHeader
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-SqlCredential [<Pscredential>]
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.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-SqlInstance [<Sqlcollaborative.Dbatools.Parameter.DbaInstanceParameter[]>]
The target SQL Server instance or instances.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-Target [<String>]
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
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
<CommonParameters>
This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer, PipelineVariable, and OutVariable. For more information, see
about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).
INPUTS
OUTPUTS
NOTES
Tags: DBCC, Statistics
Author: Patrick Flynn (@sqllensman)
Website: https://dbatools.io
Copyright: (c) 2018 by dbatools, licensed under MIT
License: MIT https://opensource.org/licenses/MIT
-------------------------- 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.
RELATED LINKS
https://dbatools.io/Get-DbaDbccStatistic