Close

2023-08-11

To list the columns of a table in MySQL

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:

  1. Using the DESCRIBE Statement:
    This is the most straightforward method to get a list of columns for a specific table.
   DESCRIBE your_table_name;
  1. Querying the INFORMATION_SCHEMA.COLUMNS Table:
    The INFORMATION_SCHEMA.COLUMNS table 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';
  1. Using the SHOW COLUMNS Command:
    This is another direct method similar to DESCRIBE.
   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.