COLUMNS 表提供关于表中列的信息。相关的 ST_GEOMETRY_COLUMNS 表提供存储空间数据的表列的信息。请参见 第 28.3.35 节,“INFORMATION_SCHEMA ST_GEOMETRY_COLUMNS 表”。The COLUMNS table provides
information about columns in tables. The related
ST_GEOMETRY_COLUMNS table provides
information about table columns that store spatial data. See
Section 28.3.35, “The INFORMATION_SCHEMA ST_GEOMETRY_COLUMNS Table”.
COLUMNS 表包含以下列:The COLUMNS table has these columns:
TABLE_CATALOG包含该列的表所属的目录名称。此值始终为
def。The name of the catalog to which the table containing the column belongs. This value is alwaysdef.TABLE_SCHEMA包含该列的表所属的模式(数据库)名称。The name of the schema (database) to which the table containing the column belongs.
TABLE_NAMETABLE_NAME包含该列的表名称。The name of the table containing the column.
COLUMN_NAMECOLUMN_NAME列名称。The name of the column.
ORDINAL_POSITION列在表中的位置。
ORDINAL_POSITION是必要的,因为你可能想要说ORDER BY ORDINAL_POSITION。与SHOW COLUMNS不同,从SELECT查询COLUMNS表不会自动排序。The position of the column within the table.ORDINAL_POSITIONis necessary because you might want to sayORDER BY ORDINAL_POSITION. UnlikeSHOW COLUMNS,SELECTfrom theCOLUMNStable does not have automatic ordering.COLUMN_DEFAULT列的默认值。如果该列有明确的
NULL默认值,或者列定义中没有包含DEFAULT子句,则此值为NULL。The default value for the column. This isNULLif the column has an explicit default ofNULL, or if the column definition includes noDEFAULTclause.IS_NULLABLE列是否可为空。如果列可以存储
NULL值,则值为YES;如果不可以,则值为NO。The column nullability. The value isYESifNULLvalues can be stored in the column,NOif not.DATA_TYPE列的数据类型。The column data type.
DATA_TYPE的值仅为类型名称,不包含其他信息。COLUMN_TYPE的值包含类型名称,并可能包含其他信息,如精度或长度。TheDATA_TYPEvalue is the type name only with no other information. TheCOLUMN_TYPEvalue contains the type name and possibly other information such as the precision or length.CHARACTER_MAXIMUM_LENGTH对于字符串列,最大字符长度。For string columns, the maximum length in characters.
CHARACTER_OCTET_LENGTH对于字符串列,最大字节长度。For string columns, the maximum length in bytes.
NUMERIC_PRECISION对于数值列,数值精度。For numeric columns, the numeric precision.
NUMERIC_SCALE对于数值列,数值刻度。For numeric columns, the numeric scale.
DATETIME_PRECISION对于时间列,小数秒精度。For temporal columns, the fractional seconds precision.
CHARACTER_SET_NAME对于字符列,字符集名称。For character string columns, the character set name.
COLLATION_NAME对于字符列,排序规则名称。For character string columns, the collation name.
COLUMN_TYPE列的数据类型。The column data type.
DATA_TYPE的值仅为类型名称,不包含其他信息。COLUMN_TYPE的值包含类型名称,并可能包含其他信息,如精度或长度。TheDATA_TYPEvalue is the type name only with no other information. TheCOLUMN_TYPEvalue contains the type name and possibly other information such as the precision or length.COLUMN_KEY该列是否有索引:Whether the column is indexed:
如果
COLUMN_KEY为空,则该列没有索引,或仅作为多列非唯一索引中的次要列被索引。IfCOLUMN_KEYis empty, the column either is not indexed or is indexed only as a secondary column in a multiple-column, nonunique index.如果
COLUMN_KEY为PRI,则该列是PRIMARY KEY,或是多列PRIMARY KEY中的一列。IfCOLUMN_KEYisPRI, the column is aPRIMARY KEYor is one of the columns in a multiple-columnPRIMARY KEY.如果
COLUMN_KEY是UNI,则该列是UNIQUE索引的第一列。(UNIQUE索引允许多个NULL值,但您可以通过查看Null列来判断该列是否允许NULL值。)IfCOLUMN_KEYisUNI, the column is the first column of aUNIQUEindex. (AUNIQUEindex permits multipleNULLvalues, but you can tell whether the column permitsNULLby checking theNullcolumn.)如果
COLUMN_KEY是MUL,则该列是非唯一索引的第一列,在该列中允许给定值的多次出现。IfCOLUMN_KEYisMUL, the column is the first column of a nonunique index in which multiple occurrences of a given value are permitted within the column.
如果一个表的某列适用多个
COLUMN_KEY值,COLUMN_KEY会显示优先级最高的一个,优先级顺序为PRI、UNI、MUL。If more than one of theCOLUMN_KEYvalues applies to a given column of a table,COLUMN_KEYdisplays the one with the highest priority, in the orderPRI,UNI,MUL.如果唯一索引不能包含
NULL值,并且表中没有PRIMARY KEY,则UNIQUE索引可能显示为PRI。如果多个列形成复合UNIQUE索引,UNIQUE索引可能显示为MUL;虽然这些列的组合是唯一的,但每列仍可以包含给定值的多个出现。AUNIQUEindex may be displayed asPRIif it cannot containNULLvalues and there is noPRIMARY KEYin the table. AUNIQUEindex may display asMULif several columns form a compositeUNIQUEindex; although the combination of the columns is unique, each column can still hold multiple occurrences of a given value.EXTRA有关给定列的任何额外信息。在以下情况下,该值非空:Any additional information that is available about a given column. The value is nonempty in these cases:
对于具有
AUTO_INCREMENT属性的列,其值为auto_increment。auto_incrementfor columns that have theAUTO_INCREMENTattribute.on update CURRENT_TIMESTAMPon update CURRENT_TIMESTAMPforTIMESTAMPorDATETIMEcolumns that have theON UPDATE CURRENT_TIMESTAMPattribute.STORED GENERATED或VIRTUAL GENERATED用于生成列。STORED GENERATEDorVIRTUAL GENERATEDfor generated columns.DEFAULT_GENERATED用于具有表达式默认值的列。DEFAULT_GENERATEDfor columns that have an expression default value.
PRIVILEGESPRIVILEGES您对该列拥有的权限。The privileges you have for the column.
COLUMN_COMMENT列定义中包含的任何注释。Any comment included in the column definition.
GENERATION_EXPRESSION对于生成列,显示用于计算列值的表达式。非生成列为空。有关生成列的信息,请参见 第 15.1.20.8 节,“CREATE TABLE 与生成列”。For generated columns, displays the expression used to compute column values. Empty for nongenerated columns. For information about generated columns, see Section 15.1.20.8, “CREATE TABLE and Generated Columns”.
SRS_ID该值适用于空间列。它包含列的
SRID值,该值指示存储在列中的值的空间参考系统。请参阅 第 13.4.1 节,“空间数据类型”,以及 第 13.4.5 节,“空间参考系统支持”。对于非空间列以及没有SRID属性的空间列,该值为NULL。This value applies to spatial columns. It contains the columnSRIDvalue that indicates the spatial reference system for values stored in the column. See Section 13.4.1, “Spatial Data Types”, and Section 13.4.5, “Spatial Reference System Support”. The value isNULLfor nonspatial columns and spatial columns with noSRIDattribute.
注意事项Notes
在
SHOW COLUMNS中,Type显示包括来自几个不同COLUMNS列的值。InSHOW COLUMNS, theTypedisplay includes values from several differentCOLUMNScolumns.CHARACTER_OCTET_LENGTH应该与CHARACTER_MAXIMUM_LENGTH相同,除非是多字节字符集。CHARACTER_OCTET_LENGTHshould be the same asCHARACTER_MAXIMUM_LENGTH, except for multibyte character sets.CHARACTER_SET_NAME可以从COLLATION_NAME推导出来。例如,如果你执行SHOW FULL COLUMNS FROM t,并且在COLLATION_NAME列看到一个值为utf8mb4_swedish_ci,那么字符集就是第一个下划线前的部分:utf8mb4。CHARACTER_SET_NAMEcan be derived fromCOLLATION_NAME. For example, if you saySHOW FULL COLUMNS FROM t, and you see in theCOLLATION_NAMEcolumn a value ofutf8mb4_swedish_ci, the character set is what appears before the first underscore:utf8mb4.
列信息也可以通过 SHOW COLUMNS 语句获取。请参见 第 15.7.7.6 节,“SHOW COLUMNS 语句”。以下语句几乎等价:Column information is also available from the
SHOW COLUMNS statement. See
Section 15.7.7.6, “SHOW COLUMNS Statement”. The following statements are
nearly equivalent:
SELECT COLUMN_NAME, DATA_TYPE, IS_NULLABLE, COLUMN_DEFAULT FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = 'tbl_name' [AND table_schema = 'db_name'] [AND column_name LIKE 'wild'] SHOW COLUMNS FROMtbl_name[FROMdb_name] [LIKE 'wild']
关于生成的不可见主键列的信息默认在此表中可见。您可以通过设置 show_gipk_in_create_table_and_information_schema
= OFF 来使这些信息隐藏。有关更多信息,请参见 第 15.1.20.11 节,“生成的不可见主键”。Information about generated invisible primary key columns is
visible in this table by default. You can cause such information
to be hidden by setting
show_gipk_in_create_table_and_information_schema
= OFF. For more information, see
Section 15.1.20.11, “Generated Invisible Primary Keys”.