- There are three ways to view the MySQL table structure:
- 1,DESC tablename;
- For example:
- To view the Jos_modules table Structure command:
- Desc Jos_modules;
- View results:
- mysql> desc jos_modules;
- +------------------+---------------------+------+-----+---------------------+----------------+
- | Field | Type | Null | Key | Default | Extra |
- +------------------+---------------------+------+-----+---------------------+----------------+
- | id | int (one) | 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 (one) unsigned | NO | | 0 | |
- | Checked_out_time | datetime | NO | | 0000-00-00 00:00:00 | |
- | Published | tinyint (1) | NO | MUL | 0 | |
- | module | varchar ( | 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:
- To view the Jos_modules table Structure command:
- Show create table jos_modules;
- View results:
- Mysql> Show create table jos_modules;
- Jos_modules | CREATE TABLE ' jos_modules ' (
- ' ID ' int (one) not NULL auto_increment,
- ' title ' text is not NULL,
- ' Content ' text is not NULL,
- ' Ordering ' int (one) not NULL DEFAULT ' 0 ',
- ' Position ' varchar DEFAULT NULL,
- ' Checked_out ' int (one) unsigned not NULL DEFAULT ' 0 ',
- ' Checked_out_time ' datetime not NULL DEFAULT ' 0000-00-00 00:00:00 ',
- ' Published ' tinyint (1) not NULL DEFAULT ' 0 ',
- ' module ' varchar DEFAULT NULL,
- ' Numnews ' int (one) not NULL DEFAULT ' 0 ',
- ' Access ' tinyint (3) unsigned not NULL DEFAULT ' 0 ',
- ' Showtitle ' tinyint (3) unsigned not NULL DEFAULT ' 1 ',
- ' Params ' text is not NULL,
- ' Iscore ' tinyint (4) not NULL DEFAULT ' 0 ',
- ' client_id ' tinyint (4) not NULL DEFAULT ' 0 ',
- ' Control ' text is not NULL,
- PRIMARY KEY (' id '),
- KEY ' published ' (' published ', ' Access '),
- KEY ' newsfeeds ' (' Module ', ' published ')
- ) Engine=myisam auto_increment=145 DEFAULT Charset=utf8
- 3, use INFORMATION_SCHEMA; SELECT * from columns where table_name=' tablename '
- For example:
- To view the Jos_modules table Structure command:
- Use INFORMATION_SCHEMA;
- SELECT * from columns where table_name=' jos_modules ';
Ways to view MySQL table structure and table creation statements