How do I list all the columns in a MySQL table?


To list all columns in a table, we can use the SHOW command. Let us first create a table.

mysql> create table ColumnsList
   -> (
   -> id int,
   -> Firstname varchar(200),
   -> LastName varchar(100),
   -> Age int,
   -> Address varchar(300),
   -> CollegeName varchar(100)
   -> );
Query OK, 0 rows affected (1.33 sec)

Syntax to list all column names.

show columns from yourTableName;

The following is the output.

mysql> show columns from ColumnsList;

The following output displays all the column names.

+-------------+--------------+------+-----+---------+-------+
| Field       | Type         | Null | Key | Default | Extra |
+-------------+--------------+------+-----+---------+-------+
| id          | int(11)      | YES  |     | NULL    |       |
| Firstname   | varchar(200) | YES  |     | NULL    |       |
| LastName    | varchar(100) | YES  |     | NULL    |       |
| Age         | int(11)      | YES  |     | NULL    |       |
| Address     | varchar(300) | YES  |     | NULL    |       |
| CollegeName | varchar(100) | YES  |     | NULL    |       |
+-------------+--------------+------+-----+---------+-------+
6 rows in set (0.00 sec)

Updated on: 30-Jul-2019

6K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements