SQL Tutorial

SQL Tutorial SQL Introduction SQL Syntax SQL Data Types SQL OPERATORS SQL COMMANDS SQL Queries

SQL Database

SQL Create Database SQL DROP Database SQL SELECT Database

SQL Table

SQL TABLE SQL CREATE TABLE SQL COPY TABLE SQL ALTER TABLE SQL DELETE SQL TRUNCATE TABLE SQL DROP TABLE SQL UPDATE TABLE SQL INSERT TABLE

SQL SELECT

SQL SELECT Statement SQL SELECT WHERE Clause SQL SELECT IN Operator SQL BETWEEN Operator SQL SELECT BETWEEN Operator SQL SELECT AND Operator SQL SELECT OR Operator SQL SELECT LIKE Operator SQL SELECT DISTINCT SQL SELECT SUM SQL SELECT MAX SQL SELECT MIN SQL SELECT AVG

SQL Clause

SQL WHERE Clause SQL GROUP BY CLAUSE SQL ORDER BY Clause SQL HAVING Clause

SQL INSERT

SQL INSERT Statement SQL INSERT INTO Statement SQL INSERT INTO SELECT

SQL JOIN

SQL JOIN SQL Inner Join SQL Left Join SQL Right Join SQL Full Join SQL CROSS Join

SQL OPERATOR

SQL Comparison SQL LOGICAL Operator SQL Cast Operator SQL Arithmetic

Difference

SQL vs NOSQL WHERE vs HAVING DELETE vs DROP GROUP BY vs ORDER BY DROP vs TRUNCATE SQL IN vs SQL EXISTS

MISC

SQL SubQuery SQL CASE Commit and Rollback in SQL Pattern Matching in SQL DDL Commands in SQL DML Commands in SQL Types of SQL Commands SQL COUNT SQL Primary Key SQL FOREIGN KEY SET Operators in SQL Check Constraint in SQL SQL EXCEPT SQL VIEW SQL WHERE Statement SQL CRUD Operation Where Condition in SQL TCL Commands in SQL Types of SQL JOINS SQL Nth Highest Salary SQL NOT OPERATOR SQL UNION ALL SQL INTERSECT SQL Data Definition Language SQL Data Manipulation Language SQL Data Control Language SQL CONSTRAINTS SQL Aggregate Operators SQL KEYS Codd’s Rules in SQL What is SQL Injection? Trigger In SQL SQL WHERE Multiple Conditions Truncate function in SQL SQL Formatter WEB SQL SQL Auto Increment Save Point in SQL space() function in SQL SQL Aggregate Functions SQL Topological Sorting SQL Injection SQL Cloning Tables SQL Aliases SQL Handling Duplicate

How To

How to use the BETWEEN operator in SQL How To Use INNER JOIN In SQL How to use LIKE in SQL How to use HAVING Clause in SQL How to use GROUP BY Clause in SQL How To Remove Duplicates In SQL How To Delete A Row In SQL How to add column in table in SQL ? How to drop a column in SQL? How to create a database in SQL? How to use COUNT in SQL? How to Create Temporary Table in SQL? How to Add Foreign Key in SQL? How to Add Comments in SQL? How To Use Group By Clause In SQL How To Use Having Clause In SQL How To Delete Column In Table How To Compare Date In SQL

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.



ADVERTISEMENT
ADVERTISEMENT