HTML CSS Bootstrap JavaScript jQuery MySQL PHP Data Mining

MySQL DESCRIBE TABLE

The DESCRIBE statement (also written as DESC) lets you inspect the structure of an existing table. It shows you each column's name, data type, whether it allows NULL values, its key role, default value, and any extra attributes like AUTO_INCREMENT. It is one of the most used commands when working with an unfamiliar database.


Syntax

DESCRIBE table_name;
-- or the shorter alias:
DESC table_name;

Both forms produce identical output.


Basic Example

DESC students;

Sample output for the students table we created earlier:

FieldTypeNullKeyDefaultExtra
idintNOPRINULLauto_increment
namevarchar(100)NONULL
emailvarchar(150)NOUNINULL
ageintYESNULL
cityvarchar(80)YESNULL
joined_atdateYESNULL

Understanding the Output Columns

ColumnWhat it tells you
FieldThe column name
TypeThe data type and size (e.g. varchar(100), int)
NullYES if NULL values are allowed; NO if the column has NOT NULL
KeyPRI = Primary Key, UNI = Unique, MUL = part of a non-unique index
DefaultThe default value used when no value is provided on insert
ExtraAdditional info like auto_increment or on update CURRENT_TIMESTAMP

Inspecting a Specific Column

You can describe a single column instead of the whole table:

DESCRIBE students email;

This returns only the row for the email column — useful when you want to quickly check the definition of one particular field.


SHOW CREATE TABLE

For the full, exact SQL that was used to create the table — including all constraints, indexes, character sets, and storage engine — use SHOW CREATE TABLE:

SHOW CREATE TABLE students;

MySQL returns the complete CREATE TABLE statement. This is extremely useful for:

  • Understanding the exact structure of an existing table
  • Copying a table definition to use as a template
  • Debugging constraint issues
  • Generating backup scripts
Tip: In MySQL Workbench, right-clicking a table in the Navigator and selecting "Send to SQL Editor → Create Statement" does the same thing as SHOW CREATE TABLE — it inserts the full CREATE statement into the query editor.

Key Points to Remember

  • DESCRIBE table_name; or DESC table_name; shows the column structure of a table.
  • The output shows each column's name, type, NULL setting, key role, default, and extras.
  • Key values: PRI = primary key, UNI = unique constraint, MUL = index.
  • Use DESCRIBE table_name column_name; to inspect a single column.
  • SHOW CREATE TABLE table_name; returns the full CREATE statement including all constraints and engine settings.