Rechercher dans le manuel MySQL
13.7.6.5 SHOW COLUMNS Syntax
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.
- +-------------+----------+------+-----+---------+----------------+
- +-------------+----------+------+-----+---------+----------------+
- +-------------+----------+------+-----+---------+----------------+
An alternative to
syntax is
tbl_name
FROM db_name
db_name.tbl_name
. These two
statements are equivalent:
The optional EXTENDED
keyword causes the
output to include information about hidden columns that MySQL
uses internally and are not accessible by users.
The optional FULL
keyword causes the output
to include the column collation and comments, as well as the
privileges you have for each column.
The LIKE
clause, if present,
indicates which column names to match. The
WHERE
clause can be given to select rows
using more general conditions, as discussed in
Section 25.42, “Extensions to SHOW Statements”.
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. The conditions under which this occurs are
described in Section 13.1.20.8, “Silent Column Specification Changes”.
SHOW COLUMNS
displays the
following values for each table column:
Field
The name of the column.
Type
The column data type.
Collation
The collation for nonbinary string columns, or
NULL
for other columns. This value is displayed only if you use theFULL
keyword.Null
The column nullability. The value is
YES
ifNULL
values can be stored in the column,NO
if not.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.If
Key
isPRI
, the column is aPRIMARY KEY
or is one of the columns in a multiple-columnPRIMARY KEY
.If
Key
isUNI
, the column is the first column of aUNIQUE
index. (AUNIQUE
index permits multipleNULL
values, but you can tell whether the column permitsNULL
by checking theNull
field.)If
Key
isMUL
, 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
Key
values applies to a given column of a table,Key
displays the one with the highest priority, in the orderPRI
,UNI
,MUL
.A
UNIQUE
index may be displayed asPRI
if it cannot containNULL
values and there is noPRIMARY KEY
in the table. AUNIQUE
index may display asMUL
if several columns form a compositeUNIQUE
index; although the combination of the columns is unique, each column can still hold multiple occurrences of a given value.Default
The default value for the column. This is
NULL
if the column has an explicit default ofNULL
, or if the column definition includes noDEFAULT
clause.Extra
Any additional information that is available about a given column. The value is nonempty in these cases:
auto_increment
for columns that have theAUTO_INCREMENT
attribute.on update CURRENT_TIMESTAMP
forTIMESTAMP
orDATETIME
columns that have theON UPDATE CURRENT_TIMESTAMP
attribute.VIRTUAL GENERATED
orVIRTUAL STORED
for generated columns.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.Comment
Any comment included in the column definition. This value is displayed only if you use the
FULL
keyword.
Table column information is also available from the
INFORMATION_SCHEMA
COLUMNS
table. See
Section 25.6, “The INFORMATION_SCHEMA COLUMNS Table”. The extended information about
hidden columns is available only using SHOW EXTENDED
COLUMNS
; it cannot be obtained from the
COLUMNS
table.
You can list a table's columns with the mysqlshow
db_name
tbl_name
command.
The DESCRIBE
statement provides
information similar to SHOW
COLUMNS
. See Section 13.8.1, “DESCRIBE Syntax”.
The SHOW CREATE TABLE
,
SHOW TABLE STATUS
, and
SHOW INDEX
statements also
provide information about tables. See Section 13.7.6, “SHOW Syntax”.
Document created the 26/06/2006, last modified the 26/10/2018
Source of the printed document:https://www.gaudry.be/en/mysql-rf-show-columns.html
The infobrol is a personal site whose content is my sole responsibility. The text is available under CreativeCommons license (BY-NC-SA). More info on the terms of use and the author.
References
These references and links indicate documents consulted during the writing of this page, or which may provide additional information, but the authors of these sources can not be held responsible for the content of this page.
The author This site is solely responsible for the way in which the various concepts, and the freedoms that are taken with the reference works, are presented here. Remember that you must cross multiple source information to reduce the risk of errors.