commands

^

Invoke-DbaDbDbccUpdateUsage

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

 

Synopsis

Execution of Database Console Command DBCC UPDATEUSAGE

Description

Executes the command DBCC UPDATEUSAGE and returns results

Reports and corrects pages and row count inaccuracies in the catalog views. These inaccuracies may cause incorrect space usage reports returned by the sp_spaceused system stored procedure.

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

Syntax

Invoke-DbaDbDbccUpdateUsage
    [-SqlInstance] <DbaInstanceParameter[]>
    [[-SqlCredential] <PSCredential>]
    [[-Database] <String[]>]
    [[-Table] <String>]
    [[-Index] <String>]
    [-NoInformationalMessages]
    [-CountRows]
    [-EnableException]
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]

 

Examples

 

Example: 1
PS C:\> Invoke-DbaDbDbccUpdateUsage -SqlInstance SqlServer2017

Runs the command DBCC UPDATEUSAGE to update the page or row counts or both for all objects in all databases for the instance SqlServer2017. Connect using Windows Authentication

Example: 2
PS C:\> Invoke-DbaDbDbccUpdateUsage -SqlInstance SqlServer2017 -Database CurrentDB

Runs the command DBCC UPDATEUSAGE to update the page or row counts or both for all objects in the CurrentDB database for the instance SqlServer2017. Connect using Windows Authentication

Example: 3
PS C:\> Invoke-DbaDbDbccUpdateUsage -SqlInstance SqlServer2017 -Database CurrentDB -Table Sometable

Connects to CurrentDB on instance SqlServer2017 using Windows Authentication and runs the command DBCC UPDATEUSAGE(SometableId) to update the page or row counts for all indexes in the table.

Example: 4
PS C:\> $cred = Get-Credential sqladmin
PS C:\> Invoke-DbaDbDbccUpdateUsage -SqlInstance SqlServer2017 -SqlCredential $cred -Database CurrentDB -Table 'SometableId -Index IndexName -NoInformationalMessages -CountRows

Connects to CurrentDB on instance SqlServer2017 using sqladmin credential and runs the command DBCC UPDATEUSAGE(SometableId, IndexName) WITH NO_INFOMSGS, COUNT_ROWS to update the page or row counts.

Example: 5
PS C:\> 'Sql1','Sql2/sqlexpress' | Invoke-DbaDbDbccUpdateUsage -WhatIf

Displays what will happen if command DBCC UPDATEUSAGE is called against all databses on Sql1 and Sql2/sqlexpress

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. If unspecified, all databases will be processed. The Name or Id of a database can be specified Database names must comply with the rules for identifiers.

Alias
Required False
Pipeline false
Default Value
-Table

The table or indexed view to process. Table and view names must comply with the rules for identifiers The Id of Table or View can be specified If not specified, all tables or indexed views will be processed

Alias
Required False
Pipeline false
Default Value
-Index

The Index to process. The Id of Index can be specified If not specified, all indexes for the specified table or view will be processed.

Alias
Required False
Pipeline false
Default Value
-NoInformationalMessages

Suppresses all informational messages.

Alias
Required False
Pipeline false
Default Value False
-CountRows

Specifies that the row count column is updated with the current count of the number of rows in the table or view.

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
-WhatIf

Shows what would happen if the cmdlet runs. The cmdlet is not run.

Alias wi
Required False
Pipeline false
Default Value
-Confirm

Prompts you for confirmation before running the cmdlet.

Alias cf
Required False
Pipeline false
Default Value

 

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