MySQL Reference Manual-obtain information about databases and tables-MySQL

Source: Internet
Author: User
MySQL Chinese Reference Manual-get database and table information if you forget the name of a database or table, or what is the structure of a given table (for example, what is its column name ), what should I do? MySQL solves this problem by providing several statements about the database and its supported tables.
  
You have seen show databases, which lists the DATABASES managed by the server. To find the DATABASE selected, use the DATABASE () function:
  
Mysql> select database ();
+ ------------ +
| DATABASE () |
+ ------------ +
| Menagerie |
+ ------------ +
  
If you have not selected any database, the result is blank.
  
To find out what table the current database contains (for example, when you cannot determine the name of a table), run the following command:
  
Mysql> show tables;
+ --------------------- +
| Tables in menagerie |
+ --------------------- +
| Event |
| Pet |
+ --------------------- +
  
If you want to know the structure of a table, the DESCRIBE command is very useful; 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 indicates the column name. Type indicates the column data Type. Null indicates whether the column can contain NULL values. Key indicates whether the column is indexed and Default indicates the Default value of the column.
  
If you have an INDEX on a table, show index from tbl_name generates information about the indexes.

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.