13.7.7.5 SHOW COLUMNS Statement语句

SHOW [EXTENDED] [FULL] {COLUMNS | FIELDS}
    {FROM | IN} tbl_name
    [{FROM | IN} db_name]
    [LIKE 'pattern' | WHERE expr]

SHOW COLUMNS displays information about the columns in a given table. SHOW COLUMNS显示给定表中列的相关信息。It also works for views. 它也适用于视图。SHOW COLUMNS displays information only for those columns for which you have some privilege.SHOW COLUMNS仅显示您具有某些权限的列的信息。

mysql> SHOW COLUMNS FROM City;
+-------------+----------+------+-----+---------+----------------+
| Field       | Type     | Null | Key | Default | Extra          |
+-------------+----------+------+-----+---------+----------------+
| ID          | int(11)  | NO   | PRI | NULL    | auto_increment |
| Name        | char(35) | NO   |     |         |                |
| CountryCode | char(3)  | NO   | MUL |         |                |
| District    | char(20) | NO   |     |         |                |
| Population  | int(11)  | NO   |     | 0       |                |
+-------------+----------+------+-----+---------+----------------+

An alternative to tbl_name FROM db_name syntax is db_name.tbl_name. db_name语法中tbl_name的另一种替代方法是db_name.tbl_nameThese two statements are equivalent:这两种语句是等价的:

SHOW COLUMNS FROM mytable FROM mydb;
SHOW COLUMNS FROM mydb.mytable;

The optional EXTENDED keyword causes the output to include information about hidden columns that MySQL uses internally and are not accessible by users.可选的EXTENDED关键字会导致输出包含有关MySQL内部使用且用户无法访问的隐藏列的信息。

The optional FULL keyword causes the output to include the column collation and comments, as well as the privileges you have for each column.可选的FULL关键字使输出包括列排序规则和注释,以及您对每个列拥有的权限。

The LIKE clause, if present, indicates which column names to match. LIKE子句(如果存在)指示要匹配的列名。The WHERE clause can be given to select rows using more general conditions, as discussed in Section 26.8, “Extensions to SHOW Statements”.WHERE子句可用于使用更一般的条件选择行,如第26.8节,“SHOW语句的扩展”所述。

The data types may differ from what you expect them to be based on a CREATE TABLE statement because MySQL sometimes changes data types when you create or alter a table. 数据类型可能与您期望的基于CREATE TABLE语句的数据类型不同,因为MySQL有时会在您创建或更改表时更改数据类型。The conditions under which this occurs are described in Section 13.1.20.7, “Silent Column Specification Changes”.发生这种情况的条件见第13.1.20.7节,“无声柱规范变更”

SHOW COLUMNS displays the following values for each table column:SHOW COLUMNS为每个表列显示以下值:

Table column information is also available from the INFORMATION_SCHEMA COLUMNS table. 表列信息也可从INFORMATION_SCHEMA COLUMNS表中获得。See Section 26.3.8, “The INFORMATION_SCHEMA COLUMNS Table”. 参见第26.3.8节,“INFORMATION_SCHEMA列表”The extended information about hidden columns is available only using SHOW EXTENDED COLUMNS; it cannot be obtained from the COLUMNS table.有关隐藏列的扩展信息仅使用SHOW EXTENDED COLUMNS可用;无法从COLUMNS表中获取。

You can list a table's columns with the mysqlshow db_name tbl_name command.可以使用mysqlshow db_name tbl_name命令列出表的列。

The DESCRIBE statement provides information similar to SHOW COLUMNS. DESCRIBE语句提供类似于SHOW COLUMNS的信息。See Section 13.8.1, “DESCRIBE Statement”.请参阅第13.8.1节,“DESCRIBE语句”

The SHOW CREATE TABLE, SHOW TABLE STATUS, and SHOW INDEX statements also provide information about tables. SHOW CREATE TABLESHOW TABLE STATUSSHOW INDEX语句还提供有关表的信息。See Section 13.7.7, “SHOW Statements”.请参阅第13.7.7节,“SHOW语句”