On this page
Warning:
As of April 12, 2019, CockroachDB v1.1 is no longer supported. For more details, refer to the Release Support Policy.
The SHOW CREATE TABLE
statement shows the CREATE TABLE
statement that would create a carbon copy of the specified table.
Required Privileges
The user must have any privilege on the target table.
Synopsis
Parameters
Parameter | Description |
---|---|
table_name |
The name of the table for which to show the CREATE TABLE statement. |
Response
Field | Description |
---|---|
Table |
The name of the table. |
CreateTable |
The CREATE TABLE statement for creating a carbon copy of the specified table. |
Example
> CREATE TABLE customers (id INT PRIMARY KEY, email STRING UNIQUE);
> CREATE TABLE products (sku STRING PRIMARY KEY, price DECIMAL(9,2));
> CREATE TABLE orders (
id INT PRIMARY KEY,
product STRING NOT NULL REFERENCES products,
quantity INT,
customer INT NOT NULL CONSTRAINT valid_customer REFERENCES customers (id),
CONSTRAINT id_customer_unique UNIQUE (id, customer),
INDEX (product),
INDEX (customer)
);
> SHOW CREATE TABLE customer;
+-----------+----------------------------------------------------+
| Table | CreateTable |
+-----------+----------------------------------------------------+
| customers | CREATE TABLE customers ( |
| | id INT NOT NULL, |
| | email STRING NULL, |
| | CONSTRAINT "primary" PRIMARY KEY (id ASC), |
| | UNIQUE INDEX customers_email_key (email ASC), |
| | FAMILY "primary" (id, email) |
| | ) |
+-----------+----------------------------------------------------+
(1 row)
> SHOW CREATE TABLE products;
+----------+--------------------------------------------------+
| Table | CreateTable |
+----------+--------------------------------------------------+
| products | CREATE TABLE products ( |
| | sku STRING NOT NULL, |
| | price DECIMAL(9,2) NULL, |
| | CONSTRAINT "primary" PRIMARY KEY (sku ASC), |
| | FAMILY "primary" (sku, price) |
| | ) |
+----------+--------------------------------------------------+
(1 row)
> SHOW CREATE TABLE orders;
+--------+------------------------------------------------------------------------------------------+
| Table | CreateTable |
+--------+------------------------------------------------------------------------------------------+
| orders | CREATE TABLE orders ( |
| | id INT NOT NULL, |
| | product STRING NOT NULL, |
| | quantity INT NULL, |
| | customer INT NOT NULL, |
| | CONSTRAINT "primary" PRIMARY KEY (id ASC), |
| | UNIQUE INDEX id_customer_unique (id ASC, customer ASC), |
| | CONSTRAINT fk_product_ref_products FOREIGN KEY (product) REFERENCES products (sku), |
| | INDEX orders_product_idx (product ASC), |
| | CONSTRAINT valid_customer FOREIGN KEY (customer) REFERENCES customers (id), |
| | INDEX orders_customer_idx (customer ASC), |
| | FAMILY "primary" (id, product, quantity, customer) |
| | ) |
+--------+------------------------------------------------------------------------------------------+
(1 row)