×

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

Where vs Having

Difference Between Where and Having The WHERE and HAVING clauses in SQL are used to filter records stored in tables in the databases. The dissimilarities between the WHERE and HAVING clause...

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 SET Keyword

This article will provide you a good understanding of the Set keyword in Structured Query Language. What is the SET keyword? The SET keyword is used to specify values for the variables....

3 minutes read.

SQL INTERSECT

SQL intersect operator is used to combine two or more SELECT statements, but it only displays the data similar to the SELECT statement. The syntax for the INTERSECT operation: SELECT COLUMN_NAME1, COLUMN_NAME2,...

3 minutes read.

How to use INNER JOIN in SQL

In this article, we will learn about the INNER JOIN concept and how to use it in SQL with the WHERE clause. What is INNER JOIN in SQL? Inner Join is a...

6 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 Formatter

As a beginner, one does not focus much on Formatting the queries while writing their code. This leads to a great confusion while referring the code in future. For a...

5 minutes read.

SQL FULL JOIN

In this section, we will help you understand the concept of the SQL FULL Join clause with a few examples. The SQL FULL Join query is executed to display the integrated...

3 minutes read.

SQL WHERE Multiple Conditions

In this topic, we will learn how to add multiple conditions using the WHERE clause. First, let's understand the concept of WHERE clause. WHERE clause is used to specify a condition while...

5 minutes read.

How to Add Comments in SQL?

How to Add Comments in SQL Comments are text notes that are incorporated into the program to make the code easier to understand. In SQL, commenting is used to explain various sections...

2 minutes read.

SQL CREATE TABLE

In SQL tutorial, we learned and created different databases. To stores data in databases, we need to create a table. To create the table, we need to use CREATE TABLE...

5 minutes read.

SQL CROSS Join

In this tutorial, we will help you understand the concept of the SQL CROSS Join clause with the few examples. The SQL CROSS Join query is used to join one or...

5 minutes read.

SQL SELECT Database

In this tutorial, we will help you to understand and learn how to select the database in SQL with the help of examples. The database user or the administrator wants to...

3 minutes read.

TCL Commands in SQL

In Structured Query Language, TCL is an abbreviation for Transaction Control Language. A single unit of work in a database is formed after the consecutive execution of commands is known...

6 minutes read.

How to add column in table in SQL ?

How to add column in table in SQL  Introduction To add a column in already created table, one needs to use the ALTER command along with the ADD clause.If in the query,...

7 minutes read.

SQL SELECT AND Operator

This SQL tutorial explains and helps us understand how to use the AND Operator in the SELECT query with examples. The AND Operator is used to fetch the table’s records if...

2 minutes read.

How to delete a row in SQL

Introduction To delete or remove the unused/unwanted rows from a table, DELETE command is used in SQL.DELETE command removes the entire record from a table.The DELETE statement can delete one or...

6 minutes read.

SQL Insert multiple rows

This article will deal with a new insertion method in SQL which inserts multiple rows at a time. Multiple records can be inserted at a time into a specific table with...

4 minutes read.

How to create a database in SQL?

How to create a database in SQL It is very necessary to create a database in order to store the data into the database.Database name must always be unique.SQL does not...

6 minutes read.

SQL Data Control Language

Data Control Language decides to whom should (which user) permit access privileges. GRANT and REVOKE are the commands of DCL. GRANT: It gives privileges to user. REVOKE: It takes back privileges from granted...

1 minute read.