Mysql Command for viewing table structure and table creation, mysql Command for viewing table structure
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
How to Write a mysql table creation statement? What is the table structure?
Create table Name
(
Id int (11) not null auto_increment, // you can check whether it is set to auto-increment.
Field name varchar (50) null,
Field Name date null,
Field name varchar (50) null,
Field name varchar (50) null,
Field name float (13, 0) null,
Field name int null,
Primary key (id) // you can specify the ID as the primary key.
) ENGINE = MyISAM AUTO_INCREMENT = 5 default charset = gbk AUTO_INCREMENT = 5;
Charset = gbk // What is the character set of your database?
For utf8 charset = utf8
How can oracle obtain the table structure, just like the desc command in mysql,
View the table structure: desc (Table Name ); the create statement for creating a table is to press Ctrl on plsql and click the table name. Then, click the "view SQL" button in the lower right corner of the page to view the table. If you do not use the tool, export the table first and then import it. When importing it, use the show = y and log options to view it!