SHOW CREATE TABLE tbl_name
Shows the CREATE TABLE
statement
that creates the named table. To use this statement, you must
have some privilege for the table. This statement also works
with views.
mysql> SHOW CREATE TABLE t\G
*************************** 1. row ***************************
Table: t
Create Table: CREATE TABLE `t` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`s` char(60) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4
As of MySQL 8.0.16, MySQL implements CHECK
constraints and SHOW CREATE TABLE
displays them. All CHECK
constraints are
displayed as table constraints. That is, a
CHECK
constraint originally specified as part
of a column definition displays as a separate clause not part of
the column definition. Example:
mysql> CREATE TABLE t1 (
i1 INT CHECK (i1 <> 0), -- column constraint
i2 INT,
CHECK (i2 > i1), -- table constraint
CHECK (i2 <> 0) NOT ENFORCED -- table constraint, not enforced
);
mysql> SHOW CREATE TABLE t1\G
*************************** 1. row ***************************
Table: t1
Create Table: CREATE TABLE `t1` (
`i1` int(11) DEFAULT NULL,
`i2` int(11) DEFAULT NULL,
CONSTRAINT `t1_chk_1` CHECK ((`i1` <> 0)),
CONSTRAINT `t1_chk_2` CHECK ((`i2` > `i1`)),
CONSTRAINT `t1_chk_3` CHECK ((`i2` <> 0)) /*!80016 NOT ENFORCED */
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
SHOW CREATE TABLE
quotes table
and column names according to the value of the
sql_quote_show_create
option.
See Section 5.1.8, “Server System Variables”.
For information about how CREATE
TABLE
statements are stored by MySQL, see
Section 13.1.20.1, “CREATE TABLE Statement Retention”.