×

SQL DROP Table

In this tutorial, we will help you to understand how to delete the table from the database in SQL with the help of examples.

The DROP TABLE query is used to drop the table schema and all the data from the table; before using the drop table query on any table, take a backup of the table because once the drop table query is used on the table, the table is lost forever. It also removes the indexes, triggers, views, and permission mentioned in the table. The DROP TABLE query cannot be rollbacked.

The syntax of the SQL DROP TABLE query is as follows:

DROP TABLE Table_Name;

Let’s understand how to use the DROP TABLE statement with the help of examples.

First, check whether the Tourist table is available or not in the database. If the Tourist table is available, we will also check the data and then use the drop table query command on the Tourist table.

To check whether the Tourist table is available, use below query as shown below:

DESC Tourist;
FieldType Null KeyDefault Extra
Tourist_IdInt(11)NOPRINULL 
Tourist_NameVarchar(40)NO NULL 
Tourist_CountryVarchar(40)NO NULL 
GenderVarchar(1)NO NULL 

We will execute the select query to check the Tourist table data.

SELECT * FROM Tourist;
Tourist_IdTourist_NameTourist_CountryGender
101PrakashIndiaM
102AmolIndiaM
103GeniferAustraliaF
104MeghannAustraliaF
105TembaSouth AfricaM
106DaneSouth AfricaF
107OdeanWest IndiesM
108RossNewZealandM
109HayleyWest IndiesF
110SophieNewZealandF

The above two results show that the tourist table is available, and now we are ready to drop the tourist table.

Example 1: Write a query to drop table Tourist.

DROP TABLE Tourist;

We removed the table, indexes, views, and permission specification for the tourist table in the above query from the database.

Now, we will execute the DESC query or the select query on the tourist table to check whether the table is removed or not from the database.

SELECT * FROM Tourist;

The output of the above query is as follows:

SQL DROP TABLE

As we can see, a tourist table doesn't exist.

We will take another example to drop the table.

First, check whether the Student_Information table is available or not in the database. If the Student_Information table is available, we will check the data and then use the drop table query command on the Student_Information table.

To check whether the Student_Information table is available, use below query as shown below:

DESC Student_Information;
FieldType Null KeyDefault Extra
Studn_info_IdInt(11)NOPRINULL 
Student_NameVarchar(40)NO NULL 
Student_GenderVarchar(01)NO NULL 
Student_AgeInt(11)NO NULL 
MarksInt(11)NO NULL 
DegreeVarchar(40)NO NULL 

We will execute the select query to check the Student_Information table data.

SELECT * FROM Student_Information;
Studn_info_IdStudent_NameStudent_GenderStudent_ageMarksDegree
1Priya ChaudharyF23560BE
2Utkarsh KulkarniM23550B.Tech
3Rakhi JainF22580MCOM
4Nikita IngaleF23620BE
5Piyush NarkhedeM22600BSC
6Pawan SharmaM24590B.COM
7Tushar MahalleM22680B.Tech
8Sakashi SharmaF21650BSC
9Gaurav GuptaM22635B.COM
10Manish KapoorM23500MCOM

The above two results show that the Student_Information table is available, and now we are ready to drop the Student_Information table.

Example 2: Write a query to drop table Student_Information.        

DROP TABLE Student_Information;

In the above query, we removed the table, indexes, views, and permission specification for the Student_Information table from the database.

Now, we will execute the DESC query or the select query on the Student_Information table to check whether the table is removed or not from the database.

SELECT * FROM Student_Information;

The output of the above query is as follows:

SQL DROP TABLE

As we can see, the Student_Information table doesn't exist.

We will take another example to drop the table.

First, check whether the TP table is available or not in the database. If the TP table is available, we will also check the data and then use the drop table query command on the TP table.

To check whether the TP table is available, use below query as shown below:

DESC TP;
FieldType Null KeyDefault Extra
TpidInt(20)YES NULL 
HistoryVarchar(30)YES NULL 
KilometerInt(30)YES NULL 
StateVarchar(15)YES NULL 
TpnameVarchar(30)YES   

We will execute the select query to check the TP table data.

SELECT * FROM TP;
TpidHistoryKilometerStateTpname
11Beauty160KarnatakaBeluru
12Monuments270KeralaKochi
13Beach360TamilNaduMarina
14History300KarnatakaChikmagalur

The above two results show that the TP table is available, and now we are ready to drop the tourist table.

Example 3: Write a query to drop table TP.

DROP TABLE TP;

In the above query, we removed the table, indexes, views, and permission specification for the TP table from the database.

Now, we will execute the DESC query or the select query on the TP table to check whether the table is removed or not from the database.

SELECT * FROM TP;

The output of the above query is as follows:

SQL DROP TABLE

As we can see, the TP table doesn’t exist.


Related Topics

space() function in SQL

 This function returns a string with a specified number of spaces. If we specify a number, it returns the strings having that specified number of spaces. SPACE Function is available...

2 minutes read.

Update Query in SQL

Update is an SQL command that is used to modify the data that in already present in database. Update is a command of DML. DML means Data Manipulation Language. Basically,...

3 minutes read.

How to compare date in SQL

In this section, we will learn about how dates can be compared in SQL. We can compare any random date with another date stored in a column of a table.This comparison...

4 minutes read.

SQL Cloning Tables

Cloning a Table: To create a copy of the table. To perform the operations, without affecting the actual table. Steps for creating a Cloning Table: Step 1: Empty Table Creation The syntax for Creating...

3 minutes read.

SQL Aliases

SQL Aliases: These are used to give a temporary name for a column or table. These are used to make tables or columns more readable. These are used to rename the table...

2 minutes read.

Commit and Rollback in SQL

In Structured Query Language, we have Data Definition Language (DDL) and Data Manipulation Language (DML) commands the same way we have Transaction Control Language (TCL) commands in the Structured Query...

4 minutes read.

SQL SET Operator

In this tutorial, we will understand the operator who falls under the SET operator in SQL with the help of different examples. The SQL SET Operator is used to merge the...

5 minutes read.

SQL Right Join

The SQL Right Join query displays all the table records and similar records from the left table. The query display zero records if it doesn’t find any similar records. If...

4 minutes read.

SQL Inner Join

In Structured Query Language, the most used join query is the Inner join query. Inner join query retrieves the records from one or more tables with similar data or records. The...

4 minutes read.

How to drop a column in SQL?

How to drop a column in SQL Introduction To delete a column from an already created table, one needs to use the ALTER command along with the DROP COLUMN clause. Syntax: ALTER TABLE tablename...

4 minutes read.

Truncate function in SQL

The TRUNCATE is a numeric function in SQL which truncates the number according to the particular decimal points. Syntax of TRUNCATE Function SELECT TRUNCATE(X, D) AS Alias_Name; In the TRUNCATE syntax, X...

4 minutes read.

SQL INSERT INTO SELECT

In this tutorial, we will help you to understand and learn how to copy records from one table and add them to another table in the SQL with the help...

5 minutes read.

SQL INSERT INTO Values

This article will help you in getting a better understanding of a very important SQL INSERT INTO VALUES function. INSERT INTO statement is used to insert or add a new record...

4 minutes read.

Pattern Matching in SQL

The LIKE in the Structured Query Language is a Logical Operator. The SQL LIKE is used within the WHERE clause in the SQL. This Like Operator is used with the...

5 minutes read.

SQL Wildcards

SQL WILDCARD CHARACTERS: SQL wild card character is used to substitute zero or more characters of a string. These characters are used with the “LIKE” operator. Wild Card Characters in SQL: %_[]^- “%” : It is...

3 minutes read.

How to Create Temporary Table in SQL?

How to Create Temporary Table in SQL  Introduction to Temporary Tables Temporary table is a table which is used to store temporary data that can be used further in the same client...

3 minutes read.

SQL SELECT MAX

The SQL Max() function is an aggregate function in SQL. This function returns the values which are greater in the condition. The condition may be a number, or it may...

5 minutes read.

SQL WHERE Statement

SQL WHERE Statement Introduction WHERE clause is used to include a condition while fetching data from tables.When you have to specify a condition that has to be obeyed while data is...

9 minutes read.

SQL Data Manipulation Language

Data Manipulation Language manipulates/make changes in data present in a table. It only affects data/records of table, not on the schema/structure of table. INSERT, UPDATE, DELETE are the commands of DML. INSERT: Stores...

2 minutes read.

SQL DROP Table

In this tutorial, we will help you to understand how to delete the table from the database in SQL with the help of examples. The DROP TABLE query is used to...

4 minutes read.