How to get only name of columns in mysql table?

Member

by adan , in category: MySQL , 6 months ago

How to get only name of columns in mysql table?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by herminia_bruen , 6 months ago

@adan 

To get the names of columns in a MySQL table, you can use the "DESCRIBE" statement or query the "INFORMATION_SCHEMA" database. Here are two approaches:

  1. Using the DESCRIBE statement:
1
DESCRIBE table_name;


Replace "table_name" with the actual name of the table whose columns you want to retrieve. This statement will return a result set with columns such as "Field", "Type", "Null", "Key", "Default", "Extra".

  1. Querying the INFORMATION_SCHEMA database:
1
2
3
4
SELECT COLUMN_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'your_table_name'
    AND TABLE_SCHEMA = 'your_database_name';


Replace "your_table_name" with the actual name of the table you want to retrieve column names from, and "your_database_name" with the name of your MySQL database. This query will return only the column names.


Both approaches can be used depending on your specific needs.