Liquibase® version 3.8.2 is now available! Get it for free.
2018 XML Announcement
News 5 Ways to Fix a Bad Database Change in Liquibase
04 Dec 2019

- and/or -

All Previous Posts >>

Change: ‘addCheckConstraint’

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

Available Attributes

NameDescriptionRequired ForSupportsSince
catalogNameName of the catalogall3.0
constraintBodyallall
constraintNameName of the check constraintallall
disabledall
schemaNameName of the schemaall
tableNameName of the table to create the check constraint onallall
validateThis is true if the check constraint has 'ENABLE VALIDATE' set, or false if the check constraint has 'ENABLE NOVALIDATE' set.all
<changeSet author="liquibase-docs" id="addCheckConstraint-example">
    <pro:addCheckConstraint catalogName="cat"
            constraintName="const_name"
            disabled="true"
            schemaName="public"
            tableName="person"
            validate="true">A String</pro:addCheckConstraint>
</changeSet>
changeSet:
  id: addCheckConstraint-example
  author: liquibase-docs
  changes:
  - addCheckConstraint:
      catalogName: cat
      constraintBody: A String
      constraintName: const_name
      disabled: true
      schemaName: public
      tableName: person
      validate: true
{
  "changeSet": {
    "id": "addCheckConstraint-example",
    "author": "liquibase-docs",
    "changes": [
      {
        "addCheckConstraint": {
          "catalogName": "cat",
          "constraintBody": "A String",
          "constraintName": "const_name",
          "disabled": true,
          "schemaName": "public",
          "tableName": "person",
          "validate": true
        }
      }]
    
  }
}

SQL Generated From Above Sample (SQL Server)

ALTER TABLE cat.[public].person ADD CONSTRAINT const_name CHECK (A String);

ALTER TABLE cat.[public].person NOCHECK CONSTRAINT const_name;

Database Support

DatabaseNotesAuto Rollback
DB2SupportedYes
DB2SupportedYes
DerbyNot SupportedYes
FirebirdNot SupportedYes
H2Not SupportedYes
HyperSQLNot SupportedYes
INGRESNot SupportedYes
InformixNot SupportedYes
MariaDBNot SupportedYes
MySQLNot SupportedYes
OracleSupportedYes
PostgreSQLSupportedYes
SQL ServerSupportedYes
SQLiteNot SupportedYes
SybaseNot SupportedYes
Sybase AnywhereNot SupportedYes