13.7.7.10 SHOW CREATE TABLE Statement语句

SHOW CREATE TABLE tbl_name

Shows the CREATE TABLE statement that creates the named table. 显示创建命名表的CREATE 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. 从MySQL 8.0.16开始,MySQL实现CHECK约束,SHOW CREATE TABLE显示这些约束。All CHECK constraints are displayed as table constraints. 所有CHECK约束都显示为表约束。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:也就是说,最初指定为列定义一部分的CHECK约束显示为单独的子句,而不是列定义的一部分。实例

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. 根据sql_quote_show_create选项的值为表名和列名加引号。See Section 5.1.8, “Server System Variables”.请参阅第5.1.8节,“服务器系统变量”

When altering the storage engine of a table, table options that are not applicable to the new storage engine are retained in the table definition to enable reverting the table with its previously defined options to the original storage engine, if necessary. 更改表的存储引擎时,不适用于新存储引擎的表选项将保留在表定义中,以便在必要时将具有先前定义选项的表恢复到原始存储引擎。For example, when changing the storage engine from InnoDB to MyISAM, InnoDB-specific options such as ROW_FORMAT=COMPACT are retained.例如,将存储引擎从InnoDB更改为MyISAM时,将保留特定于InnoDB的选项,如ROW_FORMAT=COMACT

mysql> CREATE TABLE t1 (c1 INT PRIMARY KEY) ROW_FORMAT=COMPACT ENGINE=InnoDB;
mysql> ALTER TABLE t1 ENGINE=MyISAM;
mysql> SHOW CREATE TABLE t1\G
*************************** 1. row ***************************
       Table: t1
Create Table: CREATE TABLE `t1` (
  `c1` int NOT NULL,
  PRIMARY KEY (`c1`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci ROW_FORMAT=COMPACT

When creating a table with strict mode disabled, the storage engine's default row format is used if the specified row format is not supported. 在禁用严格模式的情况下创建表时,如果不支持指定的行格式,则使用存储引擎的默认行格式。The actual row format of the table is reported in the Row_format column in response to SHOW TABLE STATUS. 表的实际行格式在Row_format列中报告,以响应SHOW TABLE STATUSSHOW CREATE TABLE shows the row format that was specified in the CREATE TABLE statement.SHOW CREATE TABLE显示CREATE TABLE语句中指定的行格式。