Skip to content

Understanding the structure of a table in MySQL is essential for efficient database management and query optimization.

How to view table structure with DESCRIBE in MySQL?

Use the DESCRIBE statement to show the structure of a table. This command reveals information about each column:

DESCRIBE your_table_name;

Replace your_table_name with the actual name of your table. This action will display details such as column names, data types, nullability, key status, default values, and additional information.

How to use SHOW COLUMNS in MySQL?

The SHOW COLUMNS command also allows you to view the table’s structure:

SHOW COLUMNS FROM your_table_name;

Executing this command lists the columns in your table along with their types, whether they can be null, their key status, default values, and other relevant details.

Query information schema for a detailed structure

Query the INFORMATION_SCHEMA.COLUMNS table to get a detailed view of each column in your table:

SELECT COLUMN_NAME, DATA_TYPE, IS_NULLABLE, COLUMN_DEFAULT, COLUMN_KEY
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'your_table_name'
AND TABLE_SCHEMA = 'your_database_name';

Substitute your_table_name and your_database_name with your table and database names, respectively. This query yields comprehensive details about each column, such as its name, data type, whether it allows null values, its default values, and key constraints.

Understand key symbols in output

In the output of DESCRIBE or SHOW COLUMNS, you’ll encounter various symbols under the “Key” column:

  • PRI for a Primary Key.
  • UNI for a Unique constraint.
  • MUL indicating that the column is indexed without a unique constraint.

Knowing what these keys represent helps you understand the indexing of data and the relationships between different tables, enhancing your database management skills.

Written by

Robert Cooper avatar

Robert Cooper

Senior Engineer at Basedash

Robert Cooper is a senior engineer at Basedash who builds full-stack product systems across SQL data infrastructure, APIs, and frontend architecture. His work focuses on application performance, developer velocity, and reliable self-hosted workflows that make data operations easier for teams at scale.

View full author profile →

Looking for an AI-native BI tool?

Basedash lets you build charts, dashboards, and reports in seconds using all your data.