commands

^

Find-DbaDbDuplicateIndex

Author Claudio Silva (@ClaudioESSilva)
Availability Windows, Linux, macOS

 

Synopsis

Find duplicate and overlapping indexes.

Description

This command will help you to find duplicate and overlapping indexes on a database or a list of databases.

On SQL Server 2008 and higher, the IsFiltered property will also be checked

Only supports CLUSTERED and NONCLUSTERED indexes.

Output: TableName IndexName KeyColumns IncludedColumns IndexSizeMB IndexType CompressionDescription (When 2008+) [RowCount] IsDisabled IsFiltered (When 2008+)

Syntax

Find-DbaDbDuplicateIndex
    [-SqlInstance] <DbaInstanceParameter[]>
    [[-SqlCredential] <PSCredential>]
    [[-Database] <Object[]>]
    [-IncludeOverlapping]
    [-EnableException]
    [<CommonParameters>]

 

Examples

 

Example: 1
PS C:\> Find-DbaDbDuplicateIndex -SqlInstance sql2005

Returns duplicate indexes found on sql2005

Example: 2
PS C:\> Find-DbaDbDuplicateIndex -SqlInstance sql2017 -SqlCredential sqladmin

Finds exact duplicate indexes on all user databases present on sql2017, using SQL authentication.

Example: 3
PS C:\> Find-DbaDbDuplicateIndex -SqlInstance sql2017 -Database db1, db2

Finds exact duplicate indexes on the db1 and db2 databases.

Example: 4
PS C:\> Find-DbaDbDuplicateIndex -SqlInstance sql2017 -IncludeOverlapping

Finds both duplicate and overlapping indexes on all user databases.

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. Options for this list are auto-populated from the server. If unspecified, all databases will be processed.

Alias
Required False
Pipeline false
Default Value
-IncludeOverlapping

If this switch is enabled, indexes which are partially duplicated will be returned. Example: If the first key column is the same between two indexes, but one has included columns and the other not, this will be shown.

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

 

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