Rechercher dans le manuel MySQL
3.4 Getting Information About Databases and Tables
What if you forget the name of a database or table, or what the structure of a given table is (for example, what its columns are called)? MySQL addresses this problem through several statements that provide information about the databases and tables it supports.
You have previously seen SHOW
DATABASES
, which lists the databases managed by the
server. To find out which database is currently selected, use the
DATABASE()
function:
If you have not yet selected any database, the result is
NULL
.
To find out what tables the default database contains (for example, when you are not sure about the name of a table), use this statement:
- +---------------------+
- | Tables_in_menagerie |
- +---------------------+
- | event |
- | pet |
- +---------------------+
The name of the column in the output produced by this statement is
always
Tables_in_
,
where db_name
db_name
is the name of the
database. See Section 13.7.6.37, “SHOW TABLES Syntax”, for more information.
If you want to find out about the structure of a table, the
DESCRIBE
statement is useful; it
displays information about each of a table's columns:
- +---------+-------------+------+-----+---------+-------+
- +---------+-------------+------+-----+---------+-------+
- +---------+-------------+------+-----+---------+-------+
Field
indicates the column name,
Type
is the data type for the column,
NULL
indicates whether the column can contain
NULL
values, Key
indicates
whether the column is indexed, and Default
specifies the column's default value. Extra
displays special information about columns: If a column was
created with the AUTO_INCREMENT
option, the
value will be auto_increment
rather than empty.
DESC
is a short form of
DESCRIBE
. See
Section 13.8.1, “DESCRIBE Syntax”, for more information.
You can obtain the CREATE TABLE
statement necessary to create an existing table using the
SHOW CREATE TABLE
statement. See
Section 13.7.6.10, “SHOW CREATE TABLE Syntax”.
If you have indexes on a table, SHOW INDEX FROM
produces information
about them. See Section 13.7.6.22, “SHOW INDEX Syntax”, for more about this
statement.
tbl_name
Document created the 26/06/2006, last modified the 26/10/2018
Source of the printed document:https://www.gaudry.be/en/mysql-rf-getting-information.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.