Describe Tables in MySQL
Introduction
When working with tables, it is important to understand their structure, including column names, data types, and constraints.
MySQL provides the DESCRIBE (or DESC) command to quickly view this information.
What is DESCRIBE
The DESCRIBE statement is used to display the structure of a table.
It shows details such as:
Column names
Data types
Whether NULL values are allowed
Key information (like PRIMARY KEY)
Default values
Basic Syntax
DESCRIBE table_name; or
DESC table_name; Both commands work the same way.
Example
DESCRIBE Students; Output may include:
| Field | Type | Null | Key | Default | Extra |
|---|---|---|---|---|---|
| id | INT | NO | PRI | NULL | auto_increment |
| name | VARCHAR(50) | YES | NULL | ||
| age | INT | YES | NULL |
Understanding the Output
Field → Column name
Type → Data type of the column
Null → Whether NULL values are allowed
Key → Indicates PRIMARY KEY or other keys
Default → Default value
Extra → Additional info (like AUTO_INCREMENT)
Why Use DESCRIBE
This command is useful when:
You want to check the table structure
You forgot column names
You are debugging queries
You are working with an existing database
Example Scenario
Before inserting data:
DESCRIBE Students; This helps you understand the required columns and their data types.
Alternative: SHOW COLUMNS
You can also use:
SHOW COLUMNS FROM Students; This provides similar information.
Common Mistakes
Typing an incorrect table name
Assuming DESCRIBE shows data (it only shows structure)
Not selecting the database before using it
Key Points to Remember
DESCRIBEshows table structureDESCis a shortcut for DESCRIBEHelps understand columns and data types
Useful for debugging and development