Notes

`DESCRIBE` (or `DESC`) Command in DBMS (MySQL) [ English ]

< Prev Next >

Introduction

In a Database Management System (DBMS), tables are created with specific columns, data types, and constraints. Sometimes it is necessary to view the structure of a table to understand its columns and properties.

The DESCRIBE command is used to display the structure of a table, including column names, data types, and other details. This command helps users quickly understand how a table is designed.

Definition

The DESCRIBE command is used to display the structure of a table in a database, including information about its columns, data types, null values, keys, default values, and extra properties.

In MySQL, the DESCRIBE command can also be written in short form as DESC.

Syntax

DESCRIBE table_name;

or

DESC table_name;

How It Works

When the DESCRIBE command is executed:

  1. The DBMS checks the selected database.
  2. It retrieves the table structure from the system catalog (metadata).
  3. The system displays detailed information about each column in the table.

Example

First select a database:

USE student_db;

Now describe the table:

DESCRIBE students;

Example Output

Field Type Null Key Default Extra
id int NO PRI NULL auto_increment
name varchar(50) YES NULL
age int YES NULL
course varchar(50) YES NULL

Explanation of Output Columns

Column Description
Field Name of the column in the table
Type Data type of the column
Null Indicates whether the column can store NULL values
Key Shows if the column is a key (PRI for Primary Key)
Default Default value assigned to the column
Extra Additional information such as auto_increment

Practical Use

The DESCRIBE command is commonly used for:

  1. Understanding table structure
  2. Checking column names and data types
  3. Verifying keys and constraints
  4. Debugging SQL queries

Key Points

Summary

The DESCRIBE command is used to display the structure of a table in a database. It provides detailed information about columns, data types, and constraints. This command is very useful for understanding how a table is organized before performing operations such as inserting or retrieving data.

< Prev Next >