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.
Execution of Database Console Command DBCC CLEANTABLE
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
Invoke-DbaDbDbccCleanTable
[-SqlInstance] <DbaInstanceParameter[]>
[[-SqlCredential] <PSCredential>]
[[-Database] <String[]>]
[[-Object] <String[]>]
[[-BatchSize] <Int32>]
[-NoInformationalMessages]
[-EnableException]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
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.
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.
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.
PS C:\> 'Sql1','Sql2/sqlexpress' | Invoke-DbaDbDbccCleanTable -Object 'dbo.SomeTable' -BatchSize 5000
Runs the command DBCC CLEANTABLE('DatabaseName', 'dbo.SomeTable', 5000) against all databases on Sql1 and Sql2/sqlexpress.
The target SQL Server instance or instances.
Alias | |
Required | True |
Pipeline | true (ByValue) |
Default Value |
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 |
The database(s) to process. If unspecified, all databases will be processed.
Alias | |
Required | False |
Pipeline | false |
Default Value |
The table(s) or indexed view(s) to be cleaned.
Alias | |
Required | False |
Pipeline | false |
Default Value |
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 |
Suppresses all informational messages.
Alias | |
Required | False |
Pipeline | false |
Default Value | False |
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 |
Shows what would happen if the cmdlet runs. The cmdlet is not run.
Alias | wi |
Required | False |
Pipeline | false |
Default Value |
Prompts you for confirmation before running the cmdlet.
Alias | cf |
Required | False |
Pipeline | false |
Default Value |