SHOW CREATE

The SHOW CREATE statement shows the CREATE statement for an existing table, view, or sequence.

Required privileges

The user must have any privilege on the target table, view, or sequence.

Synopsis

SHOWCREATEobject_name

Parameters

ParameterDescription
object_nameThe name of the table, view, or sequence for which to show the CREATE statement.

Response

FieldDescription
table_nameThe name of the table, view, or sequence.
create_statementThe CREATE statement for the table, view, or sequence.

Example

Show the CREATE TABLE statement for a table

  1. > CREATE TABLE customers (id INT PRIMARY KEY, email STRING UNIQUE);
  1. > SHOW CREATE customers;
  1. +------------+---------------------------------------------------+
  2. | table_name | create_statement |
  3. +------------+---------------------------------------------------+
  4. | customers | CREATE TABLE customers ( |
  5. | | |
  6. | | id INT NOT NULL, |
  7. | | |
  8. | | email STRING NULL, |
  9. | | |
  10. | | CONSTRAINT "primary" PRIMARY KEY (id ASC), |
  11. | | |
  12. | | UNIQUE INDEX customers_email_key (email ASC), |
  13. | | |
  14. | | FAMILY "primary" (id, email) |
  15. | | |
  16. | | ) |
  17. +------------+---------------------------------------------------+
  18. (1 row)

Show the CREATE VIEW statement for a view

  1. > SHOW CREATE bank.user_accounts;
  1. +---------------------------+--------------------------------------------------------------------------+
  2. | table_name | create_statement |
  3. +---------------------------+--------------------------------------------------------------------------+
  4. | bank.public.user_accounts | CREATE VIEW user_accounts (type, email) AS SELECT type, email FROM |
  5. | | bank.public.accounts |
  6. +---------------------------+--------------------------------------------------------------------------+
  7. (1 row)

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:

  1. > SELECT view_definition
  2. FROM information_schema.views
  3. WHERE table_name = 'user_accounts';
  1. +----------------------------------------------+
  2. | view_definition |
  3. +----------------------------------------------+
  4. | SELECT type, email FROM bank.public.accounts |
  5. +----------------------------------------------+
  6. (1 row)

Show the CREATE SEQUENCE statement for a sequence

  1. > CREATE SEQUENCE desc_customer_list START -1 INCREMENT -2;
  1. > SHOW CREATE desc_customer_list;
  1. +--------------------+--------------------------------------------------------------------------+
  2. | table_name | create_statement |
  3. +--------------------+--------------------------------------------------------------------------+
  4. | desc_customer_list | CREATE SEQUENCE desc_customer_list MINVALUE -9223372036854775808 |
  5. | | MAXVALUE -1 INCREMENT -2 START -1 |
  6. +--------------------+--------------------------------------------------------------------------+
  7. (1 row)

See also

Was this page helpful?
YesNo