FreeKB - mySQL / MariaDB List the columns in a table (show columns, describe)
mySQL / MariaDB - List the columns in a table (show columns, describe)

The show columns or describe <tablename> commands can be used to list the columns in a table. You will first need to log into your MariaDB or mySQL server or configure passwordless authentication and then use the -e command line option.

In this example, the columns in table001 in the database named db001 will be listed.

use db001; describe table001;

 

Or like this.

describe db001.table001;

 

Something like this should be returned.

+-----------------+---------------+------+-----+---------+----------------+
| Field           | Type          | Null | Key | Default | Extra          |
+-----------------+---------------+------+-----+---------+----------------+
| id              | int(11)       | NO   | PRI | NULL    | auto_increment |
| column001       | varchar(200)  | NO   |     | NULL    |                |
| column002       | varchar(1000) | NO   |     | NULL    |                |
| column003       | varchar(2000) | NO   |     | NULL    |                |
+-----------------+---------------+------+-----+---------+----------------+

 

 

Something like this should be returned.

+-----------------+---------------+------+-----+---------+----------------+
| Field           | Type          | Null | Key | Default | Extra          |
+-----------------+---------------+------+-----+---------+----------------+
| id              | int(11)       | NO   | PRI | NULL    | auto_increment |
| foo             | varchar(250)  | NO   |     | NULL    |                |
| column002       | varchar(1000) | NO   |     | NULL    |                |
| column003       | varchar(2000) | NO   |     | NULL    |                |
+-----------------+---------------+------+-----+---------+----------------+

 

Or, the show columns command can be used.

show columns from db001.table001;

 



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




Please enter 7ab9a in the box below so that we can be sure you are a human.




Comments

Web design by yours truely - me, myself, and I   |   jeremy.canfield@freekb.net   |