Creates a UNIQUE constraint on the specified column and table.
Add-UniqueKey [-SchemaName <String>] [-TableName] <String> [-ColumnName] <String[]> [-Clustered] [-FillFactor <Int32>] [-Option <String[]>] [-On <String>] [-Name <String>] [<CommonParameters>]
Creates a UNIQUE constraint on the specified column and table.
You can use UNIQUE constraints to make sure that no duplicate values are entered in specific columns that do not participate in a primary key. Although both a UNIQUE constraint and a PRIMARY KEY constraint enforce uniqueness, use a UNIQUE constraint instead of a PRIMARY KEY constraint when you want to enforce the uniqueness of a column, or combination of columns, that is not the primary key.
Name | Type | Description | Required? | Pipeline Input | Default Value |
---|---|---|---|---|---|
SchemaName | String | The schema name of the target table. Defaults to |
false | false | dbo |
TableName | String | The name of the target table. |
true | false | |
ColumnName | String[] | The column(s) on which the index is based |
true | false | |
Clustered | SwitchParameter | Creates a clustered index, otherwise non-clustered |
false | false | False |
FillFactor | Int32 | FillFactor as Integer |
false | false | 0 |
Option | String[] | An array of index options. |
false | false | |
On | String | The value of the |
false | false | |
Name | String | The name for the |
false | false |
Add-UniqueKey -TableName Cars -ColumnName Year
Adds an unique constraint on column 'Year' in the table 'Cars'
Add-UniqueKey -TableName 'Cars' -ColumnName 'Year' -Option @('IGNORE_DUP_KEY = ON','ALLOW_ROW_LOCKS = OFF')
Adds an unique constraint on column 'Year' in the table 'Cars' with specified options