Skip to main content
The SHOW CREATE statement shows the CREATE statement for an existing database, function, table, trigger, view, or sequence.

Required privileges

The user must have any privilege on the target database, function, table, view, or sequence. To run SHOW CREATE TRIGGER, the user must have any privilege on the table on which the trigger is defined.

Synopsis

show_create syntax diagram

Parameters

Response

Example

Setup

The following examples use MovR, a fictional vehicle-sharing application, to demonstrate CockroachDB SQL statements. For more information about the MovR example application and dataset, see MovR: A Global Vehicle-sharing App. To follow along, run cockroach demo with the --nodes and --demo-locality flags. This command opens an interactive SQL shell to a temporary, multi-node in-memory cluster with the movr database preloaded and set as the current database.

Show the CREATE TABLE statement for a table

To return just the create_statement value:
SHOW CREATE TABLE also lists any partitions and zone configurations defined on primary and secondary indexes of a table. If partitions are defined, but no zones are configured, the SHOW CREATE TABLE output includes a warning.

Show the CREATE TABLE statement for a table with a hidden column

If one or more columns is NOT VISIBLE within a table, SHOW CREATE will display the NOT VISIBLE flag after those columns. Start by setting the credit_card field to NOT VISIBLE:

Show the CREATE VIEW statement for a view

To return just the create_statement value:

Show just a view’s SELECT statement

To get just a view’s SELECT statement, you can query the views table in the built-in information_schema database and filter on the view name:

Show the CREATE SEQUENCE statement for a sequence

To return just the create_statement value:

Show the CREATE TABLE statement for a table with a comment

If you add a comment on a table, SHOW CREATE TABLE will display the comment.
To return just the create_statement value:
For more information, see COMMENT ON.

Show the CREATE TABLE statement for a table with a multi-region locality

Use the SHOW CREATE TABLE command to view multi-region-defined table localities. To add the first region to the database, or to set an already-added region as the primary region, use a SET PRIMARY REGION statement:
All tables will be REGIONAL BY TABLE in us-east by default. Configure the users table to be REGIONAL BY ROW instead:

Show the CREATE FUNCTION statement for a function

The following statement defines a function to return the number of rows in the users table.

Show the CREATE TRIGGER statement for a trigger

To return the CREATE TRIGGER statement for a trigger, use SHOW CREATE TRIGGER and specify the trigger name and the table on which the trigger is defined.
To list the triggers on a table, use SHOW TRIGGERS.

Show the statements needed to recreate all tables, views, and sequences in the current database

To return the CREATE statements for all of the tables, views, and sequences in the current database, use SHOW CREATE ALL TABLES. Note that this statement also returns the ALTER statements that add, modify, and validate an object’s constraints.

Show the CREATE DATABASE statement for a database

To return the CREATE DATABASE statement for a database, use SHOW CREATE DATABASE:
Suppose that you have a multi-region cluster, and you want to return the SHOW CREATE DATABASE statement for a multi-region database. In a new terminal, start a virtual multi-region demo cluster:
In the SQL shell, add regions to the database:
The SHOW CREATE DATABASE output includes the database regions.

Show the CREATE SCHEMA statement for all schemas within a database

See also