Prerequisite: SQL Create Clause
As the name suggests, DESCRIBE is used to describe something. Since in a database, we have tables, that's why do we use DESCRIBE or DESC(both are the same) commands to describe the structure of a table.
Syntax:
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 4 columns named id, name, email, and age and all are of can contain null values.
Query:
CREATE TABLE users (
id INT PRIMARY KEY,
name VARCHAR(50),
email VARCHAR(100),
age INT
);
DESC users;
Output:
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 the table is shown in the describe tab of the Database System Software.
So desc or describe command shows the structure of the table which include the name of the column, the data type of the column and the nullability which means, that column can contain null values or not.
All of these features of the table are described at the time of Creation of the table.
Creating a Table or Defining the Structure of a Table
Query:
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.
Demonstrate DESC
Step 1: Defining the structure of the table.
Creating a table:
create table one
(
id int not null,
name char(25),
city varchar2(25)
)
Step 2: Displaying the structure of the table:
Table:
DESC one
OR
DESCRIBE one
Output:
Note: Here above ID column is of not null type and rest 2 columns can contain null values. Note: You have to execute the 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 References: Oracle.com
Similar Reads
SQL CASE Statement The CASE statement in SQL is a versatile conditional expression that enables us to incorporate conditional logic directly within our queries. It allows you to return specific results based on certain conditions, enabling dynamic query outputs. Whether you need to create new columns, modify existing
4 min read
SQL CREATE VIEW Statement The SQL CREATE VIEW statement is a very powerful feature in RDBMSs that allows users to create virtual tables based on the result set of a SQL query. Unlike regular tables, these views do not store data themselves rather they provide a way of dynamically retrieving and presenting data from one or ma
4 min read
SQL USE Database Statement SQL(Structured Query Language) is a standard Database language that is used to create, maintain and retrieve the data from relational databases like MySQL, Oracle, etc. It is flexible and user-friendly. In SQL, to interact with the database, the users have to type queries that have certain syntax, a
2 min read
SQL SELECT INTO Statement The SELECT INTO statement in SQL is a powerful and efficient command that allow users to create a new table and populate it with data from an existing table or query result in a single step. This feature is especially useful for creating backups, extracting specific subsets of data, or preparing new
5 min read
Select Statement in MS SQL Server The SELECT statement in SQL Server is a foundational SQL command used for querying and retrieving data from one or more tables within a database. This command allows users to specify which columns and rows to retrieve and apply filters to focus on specific data and perform various operations to mani
4 min read