SQL | DESCRIBE Statement
Prerequisite : Sql Create Clause,
As the name suggests, DESCRIBE is used to describe something. Since in database we have tables, that’s why we use DESCRIBE or DESC(both are same) command to describe the structure of a table.
Attention reader! Don’t stop learning now. Learn SQL for interviews using SQL Course by GeeksforGeeks.
DESCRIBE one; OR DESC one;
Note : We can use either DESCRIBE or DESC(both are Case Insensitive).
Suppose our table whose name is one has 3 columns named FIRST_NAME, LAST_NAME and SALARY and all are of can contain null values.
Name Null Type FIRST_NAME CHAR(25) LAST_NAME CHAR(25) SALARY NUMBER(6)
- Here, above on using DESC or either DESCRIBE we are able to see the structure of a table but not on the console tab, the structure of table is shown in the describe tab of the Database System Software.
- So desc or describe command shows the structure of table which include name of the column, data-type of column and the nullability which means, that column can contain null values or not.
- All of these features of table are described at the time of Creation of table.
Creating table or defining the structure of a table
create table one ( id int not null, name char(25) )
Here, we created a table whose name is one and its columns are ID, NAME and the id is of not null type i.e, we can’t put null values in the ID column but we can put null values in the NAME column.
Example to demonstrate DESC:
Step 1: Defining structure of table i.e, Creating a table:
create table one ( id int not null, name char(25), city varchar2(25) )
Step 2: Displaying the structure of table:
DESC one OR DESCRIBE one
Output: Name Null Type ID Not Null INT NAME CHAR(25) CITY VARCHAR2(25)
Note: Here above ID column is of not null type and rest 2 column can contain null values.
Note: You have to execute DESC command on your system software only, because this command won’t run on any editor. Make sure to run this command on your own installed Database only
This article is contributed by Rajat Rawat 4. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.