SHOW [EXTENDED] [FULL] {COLUMNS | FIELDS}
{FROM | IN} tbl_name
[{FROM | IN} db_name]
[LIKE 'pattern' | WHERE expr]
SHOW COLUMNS显示给定表中列的相关信息。SHOW COLUMNS displays information about the columns in a given table. 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 syntax is tbl_name FROM db_namedb_name.tbl_name. db_name语法中tbl_name的另一种替代方法是db_name.tbl_name。These 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为每个表列显示以下值:
Field
The name of the column.列的名称。
Type
The column data type.列数据类型。
Collation
The collation for nonbinary string columns, or 非二进制字符串列的排序规则,其他列的排序规则为NULL for other columns. NULL。This value is displayed only if you use the 仅当使用FULL keyword.FULL关键字时,才会显示此值。
Null
The column nullability. 列的可空性。The value is 如果列中可以存储YES if NULL values can be stored in the column, NO if not.NULL值,则该值为YES,否则为NO。
Key
Whether the column is indexed:是否为列编制索引:
If 如果Key is empty, the column either is not indexed or is indexed only as a secondary column in a multiple-column, nonunique index.Key为空,则该列不编制索引,或者仅作为多列非唯一索引中的辅助列编制索引。
If 如果键为Key is PRI, the column is a PRIMARY KEY or is one of the columns in a multiple-column PRIMARY KEY.PRI,则该列为PRIMARY KEY或多列主键中的一列。
If 如果Key is UNI, the column is the first column of a UNIQUE index. Key是UNI,则该列是UNIQUE索引的第一列。(A (UNIQUE index permits multiple NULL values, but you can tell whether the column permits NULL by checking the Null field.)UNIQUE索引允许多个NULL值,但您可以通过检查NULL字段来判断列是否允许NULL。)
If 如果Key is MUL, the column is the first column of a nonunique index in which multiple occurrences of a given value are permitted within the column.Key为MUL,则该列是非唯一索引的第一列,其中允许给定值在该列中多次出现。
If more than one of the 如果有多个键值应用于表的给定列,则Key values applies to a given column of a table, Key displays the one with the highest priority, in the order PRI, UNI, MUL.Key将按PRI、UNI、MUL的顺序显示优先级最高的一个。
A 如果UNIQUE index may be displayed as PRI if it cannot contain NULL values and there is no PRIMARY KEY in the table. UNIQUE索引不能包含NULL值且表中没有PRIMARY KEY,则可以将其显示为PRI。A 如果多个列构成复合UNIQUE index may display as MUL if several columns form a composite UNIQUE index; although the combination of the columns is unique, each column can still hold multiple occurrences of a given value.UNIQUE索引,则唯一索引可能显示为MUL;虽然列的组合是唯一的,但每列仍然可以包含给定值的多个引用。
Default
The default value for the column. 列的默认值。This is 如果列的显式默认值为NULL if the column has an explicit default of NULL, or if the column definition includes no DEFAULT clause.NULL,或者列定义不包含DEFAULT子句,则该值为NULL。
Extra
Any additional information that is available about a given column. The value is nonempty in these cases:有关给定列的任何其他可用信息。在以下情况下,该值为非空:
具有auto_increment for columns that have the AUTO_INCREMENT attribute.AUTO_INCREMENT属性的列的auto_increment。
对于具有on update CURRENT_TIMESTAMP for TIMESTAMP or DATETIME columns that have the ON UPDATE CURRENT_TIMESTAMP attribute.ON UPDATE CURRENT_TIMESTAMP属性的TIMESTAMP或DATETIME列,on update CURRENT_TIMESTAMP。
生成列的VIRTUAL GENERATED or VIRTUAL STORED for generated columns.VIRTUAL GENERATED或VIRTUAL STORED。
为具有表达式默认值的列生成的默认值。DEFAULT_GENERATED for columns that have an expression default value.
Privileges
The privileges you have for the column. 您对该列拥有的权限。This value is displayed only if you use the 仅当使用FULL keyword.FULL关键字时,才会显示此值。
Comment
Any comment included in the column definition. 列定义中包含的任何注释。This value is displayed only if you use the 仅当使用FULL keyword.FULL关键字时,才会显示此值。
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 TABLE、SHOW TABLE STATUS和SHOW INDEX语句还提供有关表的信息。See Section 13.7.7, “SHOW Statements”.请参阅第13.7.7节,“SHOW语句”。