< Back

Invoke-DbaDbDbccCleanTable

Mon Jan 13, 2020 12:15 pm

NAME Invoke-DbaDbDbccCleanTable



SYNOPSIS

Execution of Database Console Command DBCC CLEANTABLE





SYNTAX

Invoke-DbaDbDbccCleanTable [-SqlInstance] <Sqlcollaborative.Dbatools.Parameter.DbaInstanceParameter[]>

[[-SqlCredential] <Pscredential>] [[-Database] <System.String[]>] [[-Object] <System.String[]>] [[-BatchSize]

<Int>] [-NoInformationalMessages <Switch>] [-EnableException <Switch>] [<CommonParameters>]





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- ... ansact-sql





PARAMETERS

-BatchSize [<Int>]

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.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-Database [<System.String[]>]

The database(s) to process. 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 [<System.String[]>]

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



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



<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

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:\\>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



RELATED LINKS

https://dbatools.io/Invoke-DbaDbDbccCleanTable