Skip to main content
The SHOW CREATE shows the CREATE statement for an existing , , , , , or .

Required privileges

The user must have any 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

ParameterDescription
object_nameThe name of the database, function, table, view, or sequence for which to show the CREATE statement.
TRIGGER trigger_name ON table_nameShow the CREATE TRIGGER statement for a on the specified table.
ALL TABLESShow the CREATE statements for all tables, views, and sequences in the current database.
This option is intended to provide the statements required to recreate the objects in the current database. As a result, SHOW CREATE ALL TABLES also returns the that add, modify, and validate an object’s . The ALTER statements follow the CREATE statements to guarantee that all objects are added before their references.
ALL SCHEMASShow the CREATE statements for all in the current database.
ALL TYPESShow the CREATE statements for all in the current database.

Response

FieldDescription
table_nameThe name of the table, view, or sequence.
database_nameThe name of the database.
function_nameThe name of the function.
trigger_nameThe name of the trigger (when running SHOW CREATE TRIGGER).
create_statementThe CREATE statement for the database, function, table, trigger, view, or sequence.

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 . To follow along, run with the and 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 .

Show the CREATE TABLE statement for a table

To return just the create_statement value:
SHOW CREATE TABLE also lists any partitions and 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 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 on a table, SHOW CREATE TABLE will display the comment.
To return just the create_statement value:
For more information, see .

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

Use the SHOW CREATE TABLE command to view table localities. To add the first region to the database, or to set an already-added region as the primary region, use a statement:
All tables will be in us-east by default. Configure the users table to be 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 , 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 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 that add, modify, and validate an object’s .

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 . In a new terminal, start a virtual multi-region demo cluster:
In the SQL shell, :
The SHOW CREATE DATABASE output includes the database regions.

Show the CREATE SCHEMA statement for all schemas within a database

See also