Add-Index

Creates a relational index on a specified table.

Syntax

Add-Index [-TableName] <String> [-Clustered] [-ColumnName <String[]>] [-Descending <Boolean[]>] [-FileStreamOn <String>] [-Include <String[]>] [-Name <String>] [-On <String>] [-Option <String[]>] [-SchemaName <String>] [-Timeout <Int32>] [-Unique] [-Where <String>] [<CommonParameters>]

Description

Creates a relational index on a specified table. An index can be created before there is data on the table. Relational indexes can be created on tables or views in another database by specifying a qualified database name.

Parameters

Name Type Description Required? Pipeline Input Default Value
Clustered SwitchParameter

Creates a clustered index, otherwise non-clustered

false False False
ColumnName String[]

The column(s) on which the index is based.

false False
Descending Boolean[]

Optional array of booleans to specify descending switch per column. Length must match ColumnName.

false False
FileStreamOn String

The value of the FILESTREAM_ON clause, which controls the placement of filestream data.

false False
Include String[]

Column names to include in the index.

false False
Name String

The name for the . If not given, a sensible name will be created.

false False
On String

The value of the ON clause, which controls the filegroup/partition to use for the index.

false False
Option String[]

An array of index options.

false False
SchemaName String

The schema name of the target table. Defaults to dbo.

false False
TableName String

The name of the target table.

true False
Timeout Int32

The number of seconds to wait for the add operation to complete. Default is 30 seconds.

false False
Unique SwitchParameter

Create a unique index on a table or view.

false False False
Where String

The filter to use when creating a filtered index.

false False

Input Types

None.

Return Values

Rivet.Operations.AddIndexOperation.

Example 1

Add-Index -TableName Cars -Column Year

Adds a relational index in 'Year' on the table 'Cars'

Example 2

Add-Index -TableName 'Cars' -Column 'Year' -Unique -Option @('IGNORE_DUP_KEY = ON','ALLOW_ROW_LOCKS = OFF')

Adds an unique relational index in 'Year' on the table 'Cars' with options to ignore duplicate keys and disallow row locks.

Example 3

Add-Index -TableName 'Cars' -Column 'Year' -Include 'Model'

Adds a relational index in 'Year' on the table 'Cars' and includes the column 'Model'