Do you think IIT Guwahati certified course can help you in your career?
No
Introduction
The DESC in SQL is used in the "ORDER BY" clause to sort query results in descending order, arranging data from highest to lowest. and it can describe a table's structure, showing column names and data types.
SQL stands for Structured Query Langauge. It is a database language mainly designed to maintain data in RDBMS(Relational Database Management System). The data in RDBMS is stored in the form of tables. It is the standard language for accessing and manipulating databases. We have multiple commands in SQL to access the database; one such command is the DESC command.
In this blog, we will discuss the desc command in SQL. We will also look at the implementation and examples for better understanding.
What is DESC Command in SQL?
A desc command is also called a describe command in SQL. The command is case-insensitive and can be used in any of the below forms.
Syntax:
Describe Table_Name;
Or
Desc Table_Name;
The above two commands perform the same function and will produce the same result.
The Table_Name here refers to the name of the table. The Describe command in SQL is used to see the table's structure. The desc command gives you complete information about the structure we have given to the table while creating it.
The database command will help us view the table in the describe tab. The table will not be available in the console of the system software.
The command shows the column name and associated data type details, i.e., int, varchar, text, float, CLOB, XML, CURSOR, etc.,also about the table's column null and not null constraint.
Describe command gives information about the attribute, the value, and the default value associated with the table.
To see the structure of the database, we will use the describe command:
SQL Query:
describe books;
Output
TABLE BOOKS
Result Set 1
Column
Null?
Type
BOOKID
-
NUMBER
BOOKNAME
-
VARCHAR2(50)
BOOKAUTHOR
-
VARCHAR2(60)
BOOKPRICE
-
NUMBER
We have created an emp table with columns as empid, ename, job, manager, sal, and deptno.
In the below table, we have empid as the primary key. The query to create the table is given below:
SQL Query:
create table emp(empid int PRIMARY KEY, ename varchar(40), job varchar(40), manager varchar(40), sal int,deptno int);
To see the structure of the database, we will use the describe command. The command will also show the primary key constraint in the structure. We will also see that because of the primary key constraint, no null values will be allowed in that column.
SQL Query
desc emp;
Output
TABLE EMP
Result Set 2
Column
Null?
Type
EMPID
NOT NULL
NUMBER
ENAME
-
VARCHAR2(40)
JOB
-
VARCHAR2(40)
MANAGER
-
VARCHAR2(40)
SAL
-
NUMBER
DEPTNO
-
NUMBER
Frequently Asked Questions
Q. What is the syntax of using the DESC command in SQL?
The syntax of using the desc command in SQL is desc table_name or describe table_name;
Q. Can you get the detail of the constraint in the table using the DESC command in SQL?
Using the DESC command, you can get complete information about the table that includes the constraint, the attribute, the null value, the primary key, etc.
Q. When can you use the DESC command in SQL?
When there is no table in the database, you can use the DESC command after creating your table. If your table already exists in the database, you can use the DESC command directly.
Conclusion
In this blog, we have discussed the DESC command in SQL. We have thoroughly addressed the use and implementation of command with a few examples.
To learn more about SQL, please refer to our blogs