The DESCRIBE TABLE statement, also written as DESC or DESCRIBE, is used in MySQL to view the structure of a table. It displays important details about table columns and their properties such as data types, nullability, default values, and key constraints.
Shows column details such as data type, nullability, and default values.
Displays key information, including primary and foreign keys.
Helps developers understand table structure for better database management.
The output provides the following details about the table columns.
fee_id: An INT column that does not allow NULL values. It is the primary key (PRI) and uses AUTO_INCREMENT.
student_id: An INT column that allows NULL values. The MUL key indicates it is part of an index and acts as a foreign key referencing student_id in the students table.
amount: A DECIMAL(8,2) column that stores numeric values with up to 8 digits in total and 2 digits after the decimal point. It cannot be NULL.
payment_date: A DATE column that allows NULL values and is part of an index (MUL).
MySQL SHOW COLUMNS Command
Another way to retrieve table structure information in MySQL is by using the SHOW COLUMNS command.
Query:
SHOW COLUMNS FROM student;
Returns table structure information similar to the DESCRIBE statement.
Displays details such as column name, data type, null values, keys, and default values.
SHOW COLUMNS presents the information in a tabular format.
DESCRIBE provides a simplified listing of the same table details.
In most cases, both commands return similar results, and users can use either based on preference.