PDF (A4) - 40.9Mb
Man Pages (TGZ) - 261.1Kb
Man Pages (Zip) - 368.3Kb
Info (Gzip) - 4.1Mb
Info (Zip) - 4.1Mb
SHOW [EXTENDED] [FULL] {COLUMNS | FIELDS} {FROM | IN}tbl_name [{FROM | IN}db_name] [LIKE 'pattern' | WHEREexpr]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.
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 istbl_name FROMdb_namedb_name.tbl_name. These two statements are equivalent:
SHOW COLUMNS FROM mytable FROM mydb;SHOW COLUMNS FROM mydb.mytable; The optionalEXTENDED keyword causes the output to include information about hidden columns that MySQL uses internally and are not accessible by users.
The optionalFULL keyword causes the output to include the column collation and comments, as well as the privileges you have for each column.
TheLIKE clause, if present, indicates which column names to match. TheWHERE clause can be given to select rows using more general conditions, as discussed inSection 28.8, “Extensions to SHOW Statements”.
The data types may differ from what you expect them to be based on aCREATE TABLE statement because MySQL sometimes changes data types when you create or alter a table. The conditions under which this occurs are described inSection 15.1.22.7, “Silent Column Specification Changes”.
SHOW COLUMNS displays the following values for each table column:
FieldThe name of the column.
TypeThe column data type.
CollationThe collation for nonbinary string columns, or
NULLfor other columns. This value is displayed only if you use theFULLkeyword.NullThe column nullability. The value is
YESifNULLvalues can be stored in the column,NOif not.KeyWhether the column is indexed:
If
Keyis empty, the column either is not indexed or is indexed only as a secondary column in a multiple-column, nonunique index.If
KeyisPRI, the column is aPRIMARY KEYor is one of the columns in a multiple-columnPRIMARY KEY.If
KeyisUNI, the column is the first column of aUNIQUEindex. (AUNIQUEindex permits multipleNULLvalues, but you can tell whether the column permitsNULLby checking theNullfield.)If
KeyisMUL, the column is the first column of a nonunique index in which multiple occurrences of a given value are permitted within the column.
If more than one of the
Keyvalues applies to a given column of a table,Keydisplays the one with the highest priority, in the orderPRI,UNI,MUL.A
UNIQUEindex 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.DefaultThe default value for the column. This is
NULLif the column has an explicit default ofNULL, or if the column definition includes noDEFAULTclause.ExtraAny additional information that is available about a given column. The value is nonempty in these cases:
auto_incrementfor columns that have theAUTO_INCREMENTattribute.on update CURRENT_TIMESTAMPforTIMESTAMPorDATETIMEcolumns that have theON UPDATE CURRENT_TIMESTAMPattribute.VIRTUAL GENERATEDorSTORED GENERATEDfor generated columns.DEFAULT_GENERATEDfor columns that have an expression default value.
PrivilegesThe privileges you have for the column. This value is displayed only if you use the
FULLkeyword.CommentAny comment included in the column definition. This value is displayed only if you use the
FULLkeyword.
Table column information is also available from theINFORMATION_SCHEMACOLUMNS table. SeeSection 28.3.8, “The INFORMATION_SCHEMA COLUMNS Table”. The extended information about hidden columns is available only usingSHOW EXTENDED COLUMNS; it cannot be obtained from theCOLUMNS table.
You can list a table's columns with themysqlshowdb_nametbl_name command.
TheDESCRIBE statement provides information similar toSHOW COLUMNS. SeeSection 15.8.1, “DESCRIBE Statement”.
TheSHOW CREATE TABLE,SHOW TABLE STATUS, andSHOW INDEX statements also provide information about tables. SeeSection 15.7.7, “SHOW Statements”.
SHOW COLUMNS includes the table's generated invisible primary key, if it has one, by default. You can cause this information to be suppressed in the statement's output by settingshow_gipk_in_create_table_and_information_schema = OFF. For more information, seeSection 15.1.22.11, “Generated Invisible Primary Keys”.
PDF (A4) - 40.9Mb
Man Pages (TGZ) - 261.1Kb
Man Pages (Zip) - 368.3Kb
Info (Gzip) - 4.1Mb
Info (Zip) - 4.1Mb