Liquibase® version 3.8.5 is now available! Get it for free.
2018 XML Announcement
News All Previous Posts >>

Subscribe for email updates

- and/or -

Change: ‘addUniqueConstraint’

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

Available Attributes

NameDescription
catalogNameName of the catalog@ v3.0E.g. 'cat'
clusteredbooleanWhether create a clustered indexSupported by: mssql
columnNamesName of the column(s) to create the unique constraint on. Comma separated if multipleE.g. 'id, name'
constraintNameName of the unique constraintE.g. 'const_name'
deferrablebooleanTrue if this constraint is deferrable, False otherwise
disabledbooleanTrue if this constraint is disabled, False otherwise
forIndexCatalogName
forIndexNameE.g. 'A String'Supported by: oracle
forIndexSchemaName
initiallyDeferredbooleanTrue if this constraint is initially deferred, False otherwise
schemaNameName of the schemaE.g. 'public'
tableNameName of the table to create the unique constraint onE.g. 'person'
tablespace'Tablespace' to create the index in. Corresponds to file group in mssqlE.g. 'A String'
validatebooleanShould be true if the unique constraint shall 'ENABLE VALIDATE' set, or false if the 'ENABLE NOVALIDATE' shall.Default: true
<changeSet author="liquibase-docs" id="addUniqueConstraint-example">
    <addUniqueConstraint catalogName="cat"
            clustered="true"
            columnNames="id, name"
            constraintName="const_name"
            deferrable="true"
            disabled="true"
            forIndexName="A String"
            initiallyDeferred="true"
            schemaName="public"
            tableName="person"
            tablespace="A String"
            validate="true"/>
</changeSet>
changeSet:
  id: addUniqueConstraint-example
  author: liquibase-docs
  changes:
  - addUniqueConstraint:
      catalogName: cat
      clustered: true
      columnNames: id, name
      constraintName: const_name
      deferrable: true
      disabled: true
      forIndexName: A String
      initiallyDeferred: true
      schemaName: public
      tableName: person
      tablespace: A String
      validate: true
{
  "changeSet": {
    "id": "addUniqueConstraint-example",
    "author": "liquibase-docs",
    "changes": [
      {
        "addUniqueConstraint": {
          "catalogName": "cat",
          "clustered": true,
          "columnNames": "id, name",
          "constraintName": "const_name",
          "deferrable": true,
          "disabled": true,
          "forIndexName": "A String",
          "initiallyDeferred": true,
          "schemaName": "public",
          "tableName": "person",
          "tablespace": "A String",
          "validate": true
        }
      }]
    
  }
}

SQL Generated From Above Sample (MySQL)

ALTER TABLE cat.person ADD CONSTRAINT const_name UNIQUE CLUSTERED (id,
 name) USING INDEX `A String`;

Database Support

DatabaseNotesAuto Rollback
DB2/LUWSupportedYes
DB2/zSupportedYes
DerbySupportedYes
FirebirdSupportedYes
H2SupportedYes
HyperSQLSupportedYes
INGRESSupportedYes
InformixSupportedYes
MariaDBSupportedYes
MySQLSupportedYes
OracleSupportedYes
PostgreSQLSupportedYes
SQL ServerSupportedYes
SQLiteNot SupportedYes
SybaseSupportedYes
Sybase AnywhereSupportedYes