MySQL query to get column names?
To get the column names of a table in MySQL, you can use the SHOW COLUMNS FROM
command.
SHOW COLUMNS FROM my_table;
This will return a result set containing the column names of the my_table
table.
You can also use the DESCRIBE
command to get the same information:
DESCRIBE my_table;
Both of these commands will return a result set with the following columns:
Field
: the name of the columnType
: the data type of the columnNull
: whether the column allowsNULL
valuesKey
: the type of index used for the column (if any)Default
: the default value for the columnExtra
: any additional information about the column (such as whether it isAUTO_INCREMENT
)