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.

Available attributes

Name Description Required for Supports
catalogName Name of the catalog all
remarks Comments stored for the table all
schemaName Name of the schema all
tableName Name of the table all all
tablespace Name of the tablespace, the table created in all

Nested properties

Name Description Required for Supports Multiple allowed
columns Column definitions

See the column tag documentation for more information
all all yes

XML example

<changeSet  author="liquibase-docs"  id="createTable-example">  
    <createTable  catalogName="cat"  
            remarks="A String"  
            schemaName="public"  
            tableName="person"  
            tablespace="A String">  
        <column  name="address"  type="varchar(255)"/>  
    </createTable>  
</changeSet>

YAML example

changeSet:  
  id:  createTable-example  
  author:  liquibase-docs  
  changes:  
  -  createTable:  
      catalogName:  cat  
      columns:  
      -  column:  
          name:  address  
          type:  varchar(255)  
      remarks:  A String  
      schemaName:  public  
      tableName:  person  
      tablespace:  A String

JSON example

{
"changeSet": {
  "id": "createTable-example",
  "author": "liquibase-docs",
  "changes": [
	{
	 "createTable": {
	 "catalogName": "cat",
	 "columns": [
	 {
	  "column": {
		"name": "address",
		"type": "varchar(255)"
	       }
	      }
	     ],
		"remarks": "A String",
		"schemaName": "public",
		"tableName": "person",
		"tablespace": "A String"
	        }
	       }
	      ]
	     }
         }

SQL example

CREATE  TABLE  cat.person  (address  VARCHAR(255)  NULL)  COMMENT='A String';  

ALTER  TABLE  cat.person  COMMENT  =  'A String';

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