MySQL DESC commands

Source: Internet
Author: User
Tags mul

Source: http://zhumeng8337797.blog.163.com/blog/static/100768914201179112318218/

1. DESC tablename;

For example, mysql> DESC jos_modules;

+ ------------------ + --------------------- + ------ + ----- + --------------------- + ---------------- +

| FIELD | type | null | key | default | extra |

+ --------------- --- + --------------------- + ------ + ----- + --------------------- + ---------------- +

| ID | int (11) | no | pri | null | auto_increment |

| Title | text | no | null |

| Content | text | no | null |

| Ordering | int (11) | no | 0 |

+ ------------------ + --------------------- + ------ + ----- + --------------------- + ---------------- +

When using the DESC Table Name of the MySQL database, there may be four values in the key column, namely '', 'pri ', 'uni', and 'mul '.
1. If the key is null, the column value can be repeated, indicating that the column has no index or a non-leading column with a non-unique composite index;
2. If the key is PRI, the column is an integral part of the primary key;
3. If the key is uni, this column is the first column (Leading column) of a unique value index, and does not contain null values );
4. if the key is Mul, the values of this column can be repeated. This column is a non-unique index leading column (the first column) or a unique index component, but can contain null values.
If the definition of a column meets multiple of the above four conditions, for example, if a column is both PRI and Uni, when "DESC table name" is used, the displayed key value displays pri-> uni-> Mul by priority. Then, PRI is displayed.
A unique index column can be displayed as PRI, and the column cannot contain null values. At the same time, the table does not have a primary key.
A unique index column can be displayed as Mul. If multiple columns constitute a unique compound index, although the combination of multiple columns of the index is unique, for example, ID + name is unique, however, no separate column can still have duplicate values, as long as ID + name is unique.



There are three ways to view the MySQL table structure:
1. DESC tablename;
For example:
Command to view the structure of the jos_modules table:
Desc jos_modules;
View results:
Mysql> DESC jos_modules;
+ ------------------ + --------------------- + ------ + ----- + --------------------- + ---------------- +
| FIELD | type | null | key | default | extra |
+ ------------------ + --------------------- + ------ + ----- + --------------------- + ---------------- +
| ID | int (11) | no | pri | null | auto_increment |
| Title | text | no | null |
| Content | text | no | null |
| Ordering | int (11) | no | 0 |
| Position | varchar (50) | Yes | null |
| Checked_out | int (11) unsigned | no | 0 |
| Checked_out_time | datetime | no | 0000-00-00 00:00:00 |
| Published | tinyint (1) | no | Mul | 0 |
| Module | varchar (50) | Yes | Mul | null |
| Numnews | int (11) | no | 0 |
| Access | tinyint (3) unsigned | no | 0 |
| Showtitle | tinyint (3) unsigned | no | 1 |
| Params | text | no | null |
| Iscore | tinyint (4) | no | 0 |
| Client_id | tinyint (4) | no | 0 |
| Control | text | no | null |
+ ------------------ + --------------------- + ------ + ----- + --------------------- + ---------------- +
2. Show create table tablename;
For example:
Command to view the structure of the jos_modules table:
Show create table jos_modules;
View results:
Mysql> show create table jos_modules;
Jos_modules | create table 'jos _ Les '(
'Id' int (11) not null auto_increment,
'Title' text not null,
'Content' text not null,
'Ordering' int (11) not null default '0 ',
'Position' varchar (50) default null,
'Checked _ out' int (11) unsigned not null default '0 ',
'Checked _ out_time 'datetime not null default '2017-00-00 00:00:00 ',
'Published' tinyint (1) not null default '0 ',
'Module' varchar (50) default null,
'Numnews' int (11) not null default '0 ',
'Access' tinyint (3) unsigned not null default '0 ',
'Showtitle' tinyint (3) unsigned not null default '1 ',
'Params' text not null,
'Iscore' tinyint (4) not null default '0 ',
'Client _ id' tinyint (4) not null default '0 ',
'Control' text not null,
Primary Key ('id '),
Key 'published' ('published', 'access '),
Key 'newsfeeds '('module', 'hhed ')
) Engine = MyISAM auto_increment = 145 default charset = utf8
3. Use information_schema; select * from columns where table_name = 'tablename'
For example:
Command to view the structure of the jos_modules table:
Use information_schema;
Select * from columns where table_name = 'jos _ Les ';
View results:
.
The second method is the best if you want to view how to create a data table.

Related Article

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.