createTable

The createTable Change Type creates a table.

Uses

You can typically use the createTable Change Type when you want to create a table in your changelog file and then deploy it to your database. It can include columns and another values listed in this documentation.

Running the createTable Change Type

To create a table for your database, follow these steps:

Step 1: Add the createTable Change Type to your changeset with the needed attributes as it is shown in the examples.

Step 2: Deploy your changeset by running the update command.

liquibase update

Now, you should see a new table.

Running the createTable Change Type with dynamic values

If you want to set and dynamically pass a specific attribute in your changelog, you can add ${your-attribute} to one or more of your changesets, and then run those changesets as shown in the following examples:

<changeSet id="1" author="liquibase">
   <createTable tableName="department">
           <column name="id" type="int">
           <constraints primaryKey="true"/>
           </column>
           <column name="dept" type="varchar(${dep.size})">
           <constraints nullable="false"/>
           </column>
           <column name="emp_id" type="int">
           <constraints nullable="false"/>
         </column>
       </createTable>
     </changeSet>
liquibase -Ddep.size=50 update
<changeSet id="2" author="liquibase">
   <createTable catalogName="department2"
          remarks="A String"
          schemaName="public"
          tableName="person"
          tablespace="${tablespace}">
        <column name="address" type="varchar(255)"/>
     </createTable>
   </changeSet>
liquibase -Dtablespace='tablespaceQA' update

Note: For more information, see changelog Property Substitution.

Available attributes

Name Description Required for Supports
catalogName The name of the catalog all
remarks The comments stored for the table all
schemaName The name of the schema all
tableName The name of the table all all
tablespace The name of the tablespace in which the table is created all

Nested properties

Name Description Required for Supports Multiple allowed
columns Column definitions

all all yes

Database support

Database Notes Auto rollback
DB2/LUW Supported Yes
DB2/z Supported Yes
Derby Supported Yes
Firebird 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
SQL Server Supported Yes
SQLite Supported Yes
Sybase Supported Yes
Sybase Anywhere Supported Yes