addUniqueConstraint
Adds a unique constraint to an existing column or set of columns.
Run addUniqueConstraint
To run this Change Type, follow these steps:
Add the Change Type to your changeset, as shown in the examples on this page.
Specify any required attributes. Use the table on this page to see which ones your database requires.
Deploy your changeset by running the
update
command:liquibase update
Available attributes
Name | Description | Required for | Supports |
| Name of the catalog | all | |
| Boolean. Whether to create a clustered index | mssql | |
| Name of the column(s) to create the unique constraint on. Comma separated if multiple | all | all |
| Name of the constraint | all | |
| Defines whether constraints are deferrable | all | |
| Boolean. Specifies whether the constraint is disabled. | all | |
| Name of the catalog of the index to associate with the constraint | all | |
| Name of the index to associate with the constraint | oracle | |
| Name of the schema of the index to associate with the constraint | all | |
| Defines whether constraints are initially deferred | all | |
| Name of the schema | all | |
| Name of the table to create the unique constraint on | all | all |
| Name of the tablespace to use for the index | all | |
| Set to | all |
Database support
Database | Notes | |
DB2/LUW | Supported | Yes |
DB2/z | Supported | Yes |
Derby | Supported | Yes |
Firebird | Supported | Yes |
Google BigQuery | Supported | Yes |
H2 | Supported | Yes |
HyperSQL | Supported | Yes |
INGRES | Supported | Yes |
Informix | Supported | Yes |
MariaDB | Supported | Yes |
MySQL | Supported | Yes |
Oracle | Supported | Yes |
PostgreSQL | Supported | Yes |
Snowflake | Supported | Yes |
SQL Server | Supported | Yes |
SQLite | Not Supported | No |
Sybase | Supported | Yes |
Sybase Anywhere | Supported | Yes |
addUniqueConstraint examples
--liquibase formatted sql
--changeset liquibase-docs:addUniqueConstraint-example
ALTER TABLE cat.person ADD CONSTRAINT const_name UNIQUE CLUSTERED (id, name) USING INDEX `A String`;