MySQL Chinese reference manual

Source: Internet
Author: User

What if you forget the name of a database or table, or the structure of a given table (for example, what is its column called)? MySQL solves this problem by providing several statements of information about the database and its supported tables.

You've seen show DATABASES, which lists the databases managed by the server. To find out which database is currently selected, use the DB () function:

mysql> SELECT DATABASE();
+------------+
| DATABASE() |
+------------+
| menagerie |
+------------+

If you have not selected any database, the result is empty.

To find out what tables the current database contains (for example, when you can't determine the name of a table), use this command:

mysql> SHOW TABLES;
+---------------------+
| Tables in menagerie |
+---------------------+
| event        |
| pet         |
+---------------------+

If you want to know the structure of a table, the describe command is very helpful; It displays information about each column of a table:

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  |    |
+---------+-------------+------+-----+---------+-------+

field displays the column name, type is the data type of the column, and NULL indicates whether the column can contain null values, and the key shows whether the column is indexed and default specifies the column defaults.

If you have an index on a table, show the index from Tbl_name generates information about them.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.