DESC Command in SQL

Learn via video course
FREE
View all courses
DBMS Course - Master the Fundamentals and Advanced Concepts
DBMS Course - Master the Fundamentals and Advanced Concepts
by Srikanth Varma
1000
5
Start Learning
DBMS Course - Master the Fundamentals and Advanced Concepts
DBMS Course - Master the Fundamentals and Advanced Concepts
by Srikanth Varma
1000
5
Start Learning
Topics Covered

Build an AI-First Career, Master the Complete Skillset

Choose from our industry-leading programs designed for career success

NSDC Certified

Modern Software and AI Engineering Program

Master full-stack development with AI integration

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Modern Data Science and ML with specialisation in AI

Advanced data science techniques with AI specialization

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Advanced AIML with Specialisation in Agentic AI

Deep dive into AIML with focus on Agentic systems

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

DevOps, Cloud & AI Platform Engineering

Build and manage AI-powered cloud infrastructure

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

AI Engineering Advanced Certification by IIT-Roorkee

Premier AI engineering certification from IIT-Roorkee

3 MonthsDuration
AI-LedCurriculum
Career SupportSupport
Program highlights
Go to Program
NSDC Certified

AI Forward Deployed Engineer Program

Full-stack engineering, production AI and client-facing consulting

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program

Overview

DESCRIBE table is a SQL command that is accountable for showing detailed information about the structure or the schema of a specific table in a database, such as the names of the columns, datatypes of the columns, and the constraints applied to those columns. This article gives a complete overview of the use of the DESC command in SQL, its syntax and related parameters, and various examples.

What is DESC Command in SQL?

As the name suggests, DESCRIBE means to show the information in detail. As we have several tables in our database, we will need a command that shows a table's structure, i.e., its column names, data types, constraints on column entries, etc. The describe table command in SQL will solve this problem.

We can either use DESC or DESCRIBE (both are case insensitive) statements, and both will return the same result.

Let us consider a table named student_marks. We can use the DESC or DESCRIBE command to find the fields of this table. Let's say the given table has three columns named ROLL_NO, NAME and MARKS. The same info can be obtained by running the desc table command as shown below:

Output:

NameTypeNULL
ROLL_NONUMBER(4)NO
NAMECHAR(25)NO
MARKSNUMBER(4)YES

Here, describe command shows the structure of the table, which includes the column's name, the column's data type, and the nullability (which means that column can contain null values or not). All of these features of the table are defined at the time of the creation of the table.

Sharpen Your Fundamentals with Free Learning

Syntax of DESC Command in SQL

SQL DESCRIBE table command uses the following syntax:

OR

We can provide the name of the table of which we want to know the details of its schema. For the above example, the command used to describe the schema of student_marks table is:

OR

The following is another syntax for describing the table, which can also help us specify some additional information.

How Scaler Transformed Careers in Different Fields

₹23L
AVG CTC
SCALER PLACEMENT PROOF

Scaler learners achieved 2.5x salary growth with average post-Scaler CTC reaching ₹23L.

11,000+placements
650+companies
Verified data
Hiring Partners:
GoogleGoogleAmazonAmazonMicrosoftMicrosoftFlipkartFlipkartAdobeAdobe1200+ more

Parameters of DESC Command in SQL

format: Specifies the additional information about the desired output. For example, if the format is “EXTENDED”, then the output also contains additional metadata such as parent database, owner etc.

table_identifier:

Specifies a table name in the database for which we want to show the structure.

partition_spec:

An optional parameter that specifies a comma-separated list of key and value pairs for partitions.

col_name:

An optional parameter that specifies the column name that needs to be specifically described.

Examples of DESC Command in SQL

Assume that we have a table named student_details in our database created as follows:

After completing the structure of the table, let us fill in some records as below:

Querying using SQL to find the details of this table by the following query:

OR

Output:

FieldTypeNULLKeyDefaultExtra
ROLL_NOint(11)NOPRIauto_increment
FIRST_NAMEvarchar(255)YES
LAST_NAMEvarchar(255)YES
CITYvarchar(255)YES
MARKSint(11)NO0

As you can notice, a default value for the MARKS column was added while creating the table. Therefore, in the above output, the DEFAULT field has 0 in the MARKS row. Similarly, for the ROLL_NO row, you can see the auto_increment value in the extra column. Note that the YES in the NULL column says that the value for that specific table column can be NULL and NO denotes that we cannot place or insert NULL values.

Let's see another example with the same student_details table created above(let's assume that the database which is storing this table is named as students), and here we will also include some additional information about the table so that we can understand the use of format, partition_spec, col_name with the describe command.

  • Case 1: Returns basic schema of table student_details.

In our case

Output:

FieldTypeNULLKeyDefaultExtra
ROLL_NOint(11)NOPRIauto_increment
FIRST_NAMEvarchar(255)YES
LAST_NAMEvarchar(255)YES
CITYvarchar(255)YES
MARKSint(11)NO0
  • Case 2: Returns basic schema of table student_details in students database.

In our case

Output:

FieldTypeNULLKeyDefaultExtra
ROLL_NOint(11)NOPRIauto_increment
FIRST_NAMEvarchar(255)YES
LAST_NAMEvarchar(255)YES
CITYvarchar(255)YES
MARKSint(11)NO0
  • Case 3: Returns the metadata for the FIRST_NAME column.

In our case

info_nameinfo_value
col_nameROLL_NO
data_typeint
NULLYES
  • Case 4: Returns additional metadata such as parent database, owner, access time etc.

In our case

Output:

FieldTypeNULLKeyDefaultExtra
ROLL_NOint(11)NOPRIauto_increment
FIRST_NAMEvarchar(255)YES
LAST_NAMEvarchar(255)YES
CITYvarchar(255)YES
MARKSint(11)NO0
# Detailed Table Information
Databasestudents
Tablestudent_details
Owner<creater_name>
Creation Time<creation_time>
Created By<creater_name>
Last Access Time<last_accessed_time>

Turn Learning into Career Growth

1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary
1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary

Conclusion

  • DESCRIBE or DESC command in SQL is responsible for showing detailed information about the structure or the schema of a table in a database, such as the names of the columns, datatypes of the columns, and the constraints applied to those columns.

  • It is used to return the basic metadata information of a table like names of columns, datatypes of columns such as VARCHAR, CHAR, INT, FLOAT, TIME, DATE, NUMBER, constraints applied on the columns such as NULL constraint which shows if the column does include null values or not.

  • It can provide additional information by making the use of format, partition_spec, or col_name with the describe command.

  • EXPLAIN command in SQL also works in a similar way as the DESCRIBE command works, and it also generates the same results.