Change: ‘addUniqueConstraint’

Adds a unique constrant to an existing column or set of columns.

Available Attributes

NameDescriptionRequired ForSupportsSince
catalogNameName of the catalogall3.0
columnNamesName of the column(s) to create the unique constraint on. Comma separated if multipleallall
constraintNameName of the unique constraintall
deferrableall
disabledall
initiallyDeferredall
schemaNameName of the schemaall
tableNameName of the table to create the unique constraint onallall
tablespace'Tablespace' to create the index in. Corresponds to file group in mssqlall
<changeSet author="liquibase-docs" id="addUniqueConstraint-example">
    <addUniqueConstraint catalogName="cat"
            columnNames="id, name"
            constraintName="const_name"
            deferrable="true"
            disabled="true"
            initiallyDeferred="true"
            schemaName="public"
            tableName="person"
            tablespace="A String"/>
</changeSet>
changeSet:
  id: addUniqueConstraint-example
  author: liquibase-docs
  changes:
  - addUniqueConstraint:
      catalogName: cat
      columnNames: id, name
      constraintName: const_name
      deferrable: true
      disabled: true
      initiallyDeferred: true
      schemaName: public
      tableName: person
      tablespace: A String
{
  "changeSet": {
    "id": "addUniqueConstraint-example",
    "author": "liquibase-docs",
    "changes": [
      {
        "addUniqueConstraint": {
          "catalogName": "cat",
          "columnNames": "id, name",
          "constraintName": "const_name",
          "deferrable": true,
          "disabled": true,
          "initiallyDeferred": true,
          "schemaName": "public",
          "tableName": "person",
          "tablespace": "A String"
        }
      }]
    
  }
}

SQL Generated From Above Sample (MySQL)

ALTER TABLE cat.person ADD CONSTRAINT const_name UNIQUE (id,
 name);

Database Support

DatabaseNotesAuto Rollback
DB2SupportedYes
DerbySupportedYes
FirebirdSupportedYes
H2SupportedYes
HyperSQLSupportedYes
InformixSupportedYes
MySQLSupportedYes
OracleSupportedYes
PostgreSQLSupportedYes
SQL ServerSupportedYes
SQLiteNot SupportedYes
SybaseSupportedYes
Sybase AnywhereSupportedYes

Missing, incomplete or wrong information? Please send a pull request