To list the columns of a table in MySQL

To list the columns of a table in MySQL, you can use the DESCRIBE statement or query the INFORMATION_SCHEMA.COLUMNS table. Here are the methods:
- Using the
DESCRIBEStatement:
This is the most straightforward method to get a list of columns for a specific table.
DESCRIBE your_table_name;
- Querying the
INFORMATION_SCHEMA.COLUMNSTable:
TheINFORMATION_SCHEMA.COLUMNStable provides metadata about columns in all tables in the database.
SELECT COLUMN_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA = 'your_database_name'
AND TABLE_NAME = 'your_table_name';
- Using the
SHOW COLUMNSCommand:
This is another direct method similar toDESCRIBE.
SHOW COLUMNS FROM your_table_name;
Replace your_table_name with the name of your table and your_database_name with the name of your database. These methods will give you a list of columns in the specified table.