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:

FieldTypeNullKeyDefaultExtra
idINTNOPRINULLauto_increment
nameVARCHAR(50)YESNULL
ageINTYESNULL

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

  • DESCRIBE shows table structure

  • DESC is a shortcut for DESCRIBE

  • Helps understand columns and data types

  • Useful for debugging and development