MySQL View table Structure Simple command

Source: Internet
Author: User
Tags mysql view

I. Simple description table structure, field type

Desc Tabl_name;

Displays the table structure, the field type, the primary key, whether it is empty, and so on, but does not display foreign keys.

For example: DESC table_name

Second, the query table column of the comment information

SELECT * FROM Information_schema.columns
where Table_schema = ' db ' #表所在数据库
and table_name = ' tablename '; #你要查的表

For example:

can automatically select the information you need

Querying column names and comments only
Select column_name, column_comment from information_schema.columnswhere table_schema = ' db ' and table_name = ' tablename ';

For example:

Iv. #查看表的注释
Select Table_name,table_comment from Information_schema.tableswhere table_schema = ' db ' and table_name = ' tablename '

For example:


V. View the DDL generated by the table

Show CREATE TABLE table_name;

For example:

Although this command is not very easy to see, this is not a problem can be \g to the end, making the results easy to read; The command displays the DDL that created the table, so the table structure, type, foreign key, and comments are all displayed.

I prefer this command: the input is simple and the results are comprehensive.

Add some of the commands you might use:

Build Table command:
CREATE TABLE ' T_sold_order ' (
' id ' int (one) not NULL auto_increment,
The ' DT ' date DEFAULT NULL COMMENT ' Date ',
' Hour ' tinyint (2) DEFAULT ' 0 ' COMMENT ' hours ',
' Hour_order ' int (one) DEFAULT ' 0 ' COMMENT ' hour order number ',
' Total_order ' int (one) DEFAULT ' 0 ' COMMENT ' total number of orders ',
' Prediction ' int (one) DEFAULT ' 0 ' COMMENT ' forecast order number ',
PRIMARY KEY (' id '),
UNIQUE KEY ' dt_hour ' (' dt ', ' hour ')
) Engine=innodb auto_increment=1 DEFAULT charset=utf8comment= ' Live Order Count '

Table Operation Commands:
Duplicate table structure: CREATE TABLE table1 like table;
Copy data: INSERT INTO table1 select * FROM table

Machine Authorization:
Grant SELECT On * * to ' reader ' @ '% ' identified by ' 123456 ' withgrant OPTION
Flush Privileges

Query data is inserted directly
Insert into T_visual_user_domain (' user_id ', ' domain ', ' group ') Selectid, ' www.baidu.com ' as domain, ' group ' from t_visual _user;

Modify Table Structure
ALTER TABLE Competitor_goods add sku_id bigint (a) unsigned defaultnull COMMENT ' commodity Sales Code ';

MySQL View table Structure Simple command

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.