To show the columns of a table in MySQL, you can use the DESCRIBE statement or the SHOW COLUMNS statement. Both statements provide information about the columns and their attributes in a table. Here's how you can use them:
1. Using the DESCRIBE statement:
Syntax:
DESCRIBE table_name;
Example:
DESCRIBE employees;
This statement will display information about the columns of the "employees" table, including the column name, data type, nullability, and any additional attributes.
2. Using the SHOW COLUMNS statement: Syntax:
SHOW COLUMNS FROM table_name;
Example:
SHOW COLUMNS FROM employees;
This statement will retrieve information about the columns of the "employees" table, including the column name, data type, nullability, default value, and any additional attributes.
Both DESCRIBE and SHOW COLUMNS statements provide similar output. The choice between them is a matter of preference. Executing either statement will result in a result set that displays information about the columns of the specified table.
Remember to replace table_name with the actual name of the table for which you want to show the columns.
Note: In addition to the above methods, you can also query the INFORMATION_SCHEMA.COLUMNS table to retrieve column information programmatically.