Mysql Command for viewing table structure and table Creation

Source: Internet
Author: User

Mysql Command for viewing table structure and table Creation

1, desc tablename;

mysql> desc authors;+-------+--------------+------+-----+---------+----------------+| Field | Type         | Null | Key | Default | Extra          |+-------+--------------+------+-----+---------+----------------+| id    | int(11)      | NO   | PRI | NULL    | auto_increment || email | varchar(100) | NO   | UNI | NULL    |                || name  | varchar(100) | NO   |     | NULL    |                |+-------+--------------+------+-----+---------+----------------+3 rows in set
2, show create table tablename;
mysql> show create table authors;+---------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+| Table   | Create Table                                                                                                                                                                                                                           |+---------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+| authors | CREATE TABLE `authors` (  `id` int(11) NOT NULL AUTO_INCREMENT,  `email` varchar(100) NOT NULL,  `name` varchar(100) NOT NULL,  PRIMARY KEY (`id`),  UNIQUE KEY `email` (`email`)) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 |+---------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+1 row in set
3, select * from columns where table_name = 'table name'

Mysql> use information_schema;
Database changed
Mysql> select * from columns where table_name = 'authors ';
+ Domains + -------------- + ------------ + ------------- + domains + ----------- + domains + -------------- + ------------ + domains +
| TABLE_CATALOG | TABLE_SCHEMA | TABLE_NAME | COLUMN_NAME | comment | COLUMN_DEFAULT | comment | DATA_TYPE | comment | NUMERIC_PRECISION | NUMERIC_SCALE | comment | COLLATION_NAME | COLUMN_TYPE | COLUMN_KEY | EXTRA | comment | COLUMN_COMMENT |
+ Domains + -------------- + ------------ + ------------- + domains + ----------- + domains + -------------- + ------------ + domains +
| Def | zqad | authors | id | 1 | NULL | NO | int | NULL | 10 | 0 | NULL | int (11) | PRI | auto_increment | select, insert, update, references |
| Def | zqad | authors | email | 2 | NULL | NO | varchar | 100 | 300 | NULL | utf8 | utf8_general_ci | varchar (100) | UNI | select, insert, update, references |
| Def | zqad | authors | name | 3 | NULL | NO | varchar | 100 | 300 | NULL | utf8 | utf8_general_ci | varchar (100) | select, insert, update, references |
+ Domains + -------------- + ------------ + ------------- + domains + ----------- + domains + -------------- + ------------ + domains +
3 rows in set

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.