How can we get a list of columns in an existing MySQL table?


Suppose if we forgot the names of the columns in an existing table then we can use SHOW COLUMNS statement as follows to get the list of columns −

mysql> SHOW COLUMNS from Employee\G

*************************** 1. row ***************************
  Field: Id
   Type: int(11)
   Null: YES
    Key:
Default: NULL
  Extra:
*************************** 2. row ***************************
  Field: Name
   Type: varchar(20)
   Null: YES
    Key:
Default: NULL
  Extra:

2 rows in set (0.07 sec)

In the example above, we got the list of columns of ‘Employee’ table with the help of SHOW COLUMNS statement.

Updated on: 29-Jan-2020

208 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements