commands

^

Invoke-DbaDbDbccCleanTable

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

 

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

Synopsis

Execution of Database Console Command DBCC CLEANTABLE

Description

Executes the command DBCC CLEANTABLE 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

Invoke-DbaDbDbccCleanTable
    [-SqlInstance] <DbaInstanceParameter[]>
    [[-SqlCredential] <PSCredential>]
    [[-Database] <String[]>]
    [[-Object] <String[]>]
    [[-BatchSize] <Int32>]
    [-NoInformationalMessages]
    [-EnableException]
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]

 

Examples

 

Example: 1
PS C:\> Invoke-DbaDbDbccCleanTable -SqlInstance SqlServer2017 -Database CurrentDB -Object 'dbo.SomeTable'

Connects to CurrentDB on instance SqlServer2017 using Windows Authentication and runs the command DBCC CLEANTABLE('CurrentDB', 'dbo.SomeTable') to reclaim space after variable-length columns have
been dropped.

Example: 2
PS C:\> Invoke-DbaDbDbccCleanTable -SqlInstance SqlServer2017 -Database CurrentDB -Object 34636372 -BatchSize 5000

Connects to CurrentDB on instance SqlServer2017 using Windows Authentication and runs the command DBCC CLEANTABLE('CurrentDB', 34636372, 5000) to reclaim space from table with Table_Id = 34636372
after variable-length columns have been dropped.

Example: 3
PS C:\> $cred = Get-Credential sqladmin
PS C:\> Invoke-DbaDbDbccCleanTable -SqlInstance SqlServer2017 -SqlCredential $cred -Database CurrentDB -Object 'dbo.SomeTable'  -NoInformationalMessages

Connects to CurrentDB on instance SqlServer2017 using sqladmin credential and runs the command DBCC CLEANTABLE('CurrentDB', 'dbo.SomeTable') WITH NO_INFOMSGS to reclaim space after variable-length
columns have been dropped.

Example: 4
PS C:\> 'Sql1','Sql2/sqlexpress' | Invoke-DbaDbDbccCleanTable -Object 'dbo.SomeTable' -BatchSize 5000

Runs the command DBCC CLEANTABLE('DatabaseName', 'dbo.SomeTable', 5000) 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.

Alias
Required False
Pipeline false
Default Value
-Object

The table(s) or indexed view(s) to be cleaned.

Alias
Required False
Pipeline false
Default Value
-BatchSize

Is the number of rows processed per transaction. If not specified, or if 0 is specified, the statement processes the whole table in one transaction.

Alias
Required False
Pipeline false
Default Value 0
-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
-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