SHOW CREATE TABLE 语句 用于显示创建表的 CREATE TABLE 语句

所需权限

用户需拥有这个表的任一权限

概要

图片

参数

Parameter Description
table_name 要显示CREATE TABLE 语句的表名

返回

Field Description
Table 表名
CreateTable 创建一个表的CREATE TABLE 语句

例子

> 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)

See Also