How to use DESCRIBE statement to Get Column Names In MySQL
To get column names, we mainly use the DESCRIBE statement. This command returns a list of columns in the specified table, along with their types and other details.
Syntax
DESCRIBE table_name;
Example
Suppose we have a table named `jobs` with columns `id `, `jobtitle`, `company`, `location`, `experienceInYear `, `salaryInLPA`, and `jobdescription`. Using DESCRIBE, we get:
DESCRIBE jobs;
Output:
The output contains follows:
- Field: Its displays the column names (`id`, `jobs` with columns `id `, `jobtitle` , `company` , `location` , `experienceInYear `, `salaryInLPA`, `jobdescription`).
- Type: It Indicates the data type of each column (int(11), varchar(50)).
- Null: It specifies whether the column allows NULL values (YES or NO).
- Key: This Indicates if the column is part of any key (e.g., PRI for primary key).
- Default: This Shows the default value for the column.
- Extra: Provides additional information, such as auto-increment for the id column.
How to Get Column Names in MySQL?
To get column names in MySQL use techniques such as the DESCRIBE statement, INFORMATION_SCHEMA.COLUMNS, and SHOW COLUMNS FROM commands.
Here will cover these techniques, with explained examples, and help to get a better understanding on how to get column names in MySQL.