Describe Command in SQL
Learn what is the use of describe command in SQL. This comment gives information about the fields in a table.
Ex:
CREATE TABLE EMPLOYEE (
empId INTEGER PRIMARY KEY,
name TEXT NOT NULL,
dept TEXT NOT NULL
);
Here, we have created the table “EMPLOYEE” and created columns like empId, name, dept.
To describe this table we must follow the below syntax:
Syntax:
DESCRIBE tableName;
Ex:
DESCRIBE EMPLOYEE;
Output:
This command shows COLUMNS FROM EMPLOYEE; gives the same information as DESCRIBE EMPLOYEE; but DESCRIBE involves less typing. Short-form DESC can also be used to describe a table.
- Fields column shows the EMPLOYEE column names like empId, name,and dept.
- The type column shows the EMPLOYEE data types like int, text, and text.
- The null column shows which field has a null value.
- The key column shows which field has the primary key. Here, we set empId to a primary key. So, it shows only PRI which means primary key as empId.
- Default column shows which fields have default values.
So, the describe is only for the describe the table. This comment is using rarely by the programmers. But it is very useful learning for beginners. I hope you have understood a little about describe-commend in this article. If you have any doubts about this then please comment below.