8.5 Getting information about databases and tablesWhat if you forget the name of a database or table, or what the structure of a given table is (e.g., what its columns are called)? MySQL addresses this problem through several statements that provide information about the databases and tables it supports.
You have already seen mysql> SELECT DATABASE(); +------------+ | DATABASE() | +------------+ | menagerie | +------------+ If you haven't selected any database yet, the result is blank. To find out what tables the current database contains (for example, when you're not sure about the name of a table), use this command: mysql> SHOW TABLES; +---------------------+ | Tables in menagerie | +---------------------+ | event | | pet | +---------------------+
If you want to find out about the structure of a table, the mysql> DESCRIBE pet; +---------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +---------+-------------+------+-----+---------+-------+ | name | varchar(20) | YES | | NULL | | | owner | varchar(20) | YES | | NULL | | | species | varchar(20) | YES | | NULL | | | sex | char(1) | YES | | NULL | | | birth | date | YES | | NULL | | | death | date | YES | | NULL | | +---------+-------------+------+-----+---------+-------+
If you have indexes on a table,
|