How do I show the schema of a table in a MySQL database? How do I show the schema of a table in a MySQL database? mysql mysql

How do I show the schema of a table in a MySQL database?


For formatted output:

describe [db_name.]table_name;

For an SQL statement that can be used to create a table:

show create table [db_name.]table_name;


SHOW CREATE TABLE yourTable;

or

SHOW COLUMNS FROM yourTable;


You can also use shorthand for describe as desc for table description.

desc [db_name.]table_name;

or

use db_name;
desc table_name;

You can also use explain for table description.

explain [db_name.]table_name;

See official doc

Will give output like:

+----------+-------------+------+-----+---------+-------+| Field    | Type        | Null | Key | Default | Extra |+----------+-------------+------+-----+---------+-------+| id       | int(10)     | NO   | PRI | NULL    |       || name     | varchar(20) | YES  |     | NULL    |       || age      | int(10)     | YES  |     | NULL    |       || sex      | varchar(10) | YES  |     | NULL    |       || sal      | int(10)     | YES  |     | NULL    |       || location | varchar(20) | YES  |     | Pune    |       |+----------+-------------+------+-----+---------+-------+