Creates a lookup table containing values stored in a column and creates a foreign key to the new table.

Run addLookupTable

To run this Change Type, follow these steps:

  1. Add the Change Type to your changeset, as shown in the examples on this page.
  2. Specify any required attributes. Use the table on this page to see which ones your database requires.
  3. Deploy your changeset by running the update command:
  4. liquibase update

Available attributes

Name Description Required for Supports
constraintName Name of the constraint (FOREIGN KEY CONSTRAINT) to create between the existing table and the lookup table all
existingColumnName Name of the column containing the data to extract all all
existingTableCatalogName Name of the catalog of the existing table all
existingTableName Name of the table containing the data to extract all all
existingTableSchemaName Name of the schema of the existing table all

Data type of the column.

To help make scripts database-independent, Liquibase automatically converts the following generic data types to the correct database implementation: BIGINT, BLOB, BOOLEAN, CHAR, CLOB, CURRENCY, DATE, DATETIME, DECIMAL, DOUBLE, FLOAT, INT, MEDIUMINT, NCHAR, NUMBER, NVARCHAR, SMALLINT, TIME, TIMESTAMP, TINYINT, UUID, VARCHAR, XML.

Also, specifying a java.sql.Types.* type is converted to the correct type as well. For example:

  • java.sql.Types.TIMESTAMP
  • java.sql.Types.VARCHAR(255)
informix, mariadb, mssql, mysql all
newColumnName Name of the column in the new table to create all all
newTableCatalogName Name of the catalog of the table to create all
newTableName Name of the table to create all all
newTableSchemaName Name of the schema of the table to create all



    <changeSet  author="liquibase-docs"  id="addLookupTable-example">
        <addLookupTable  constraintName="fk_address_state"

-  changeSet:
    id:  addLookupTable-example
    author:  liquibase-docs
    -  addLookupTable:
        constraintName:  fk_address_state
        existingColumnName:  state
        existingTableName:  address
        newColumnDataType:  char(2)
        newColumnName:  abbreviation
        newTableCatalogName:  cat
        newTableName:  state
        newTableSchemaName:  public
    "databaseChangeLog": [
            "changeSet": {
                "id": "addLookupTable-example",
                "author": "liquibase-docs",
                "changes": [
                        "addLookupTable": {
                            "constraintName": "fk_address_state",
                            "existingColumnName": "state",
                            "existingTableName": "address",
                            "newColumnDataType": "char(2)",
                            "newColumnName": "abbreviation",
                            "newTableCatalogName": "cat",
                            "newTableName": "state",
                            "newTableSchemaName": "public"
--liquibase formatted sql

--changeset liquibase-docs:addLookupTable-example
CREATE  TABLE  cat.state  AS  SELECT  DISTINCT  state  AS  abbreviation  FROM  address  WHERE  state  IS  NOT  NULL;
ALTER  TABLE  public.state  MODIFY  abbreviation  CHAR(2)  NOT  NULL;  
ALTER  TABLE  public.state  ADD  PRIMARY  KEY  (abbreviation);  
ALTER  TABLE  address  ADD  CONSTRAINT  fk_address_state  FOREIGN  KEY  (state)  REFERENCES  public.state  (abbreviation);

Database support

Database Notes Auto Rollback
DB2/LUW Supported Yes
DB2/z Supported Yes
Derby Supported Yes
Firebird Not Supported No
H2 Supported Yes
HyperSQL Not Supported No
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