×

DELETE VS DROP in SQL

This page contains all the information about the Delete command and Drop command concept and the difference between the DELETE and DROP commands in SQL.

What is the DELETE command in SQL?

The DELETE is a Data Manipulation Language command in the SQL, which is used to remove one record or all the records from the table. The WHERE clause is used in the DELETE query to remove specific records from the tables

The syntax of the DELETE command is:

DELETE FROM Table_Name;

The above syntax is used to remove all the records from the tuples.

The syntax of the DELETE command to remove specific records is as follows:

DELETE FROM Table_Name WHERE Expression;

Example of the DELETE command

Consider the already existing table name Diploma_Student:

Student_IdStudent_NameFirst_SemSecond_SemThird_SemFourth_SemFifth_SemSixth_SemTotalDepartment_Id
202111Vaishnavi Patil949188859592911
202112Vaibhav Lokhande859092808582862
202113Yash Dhull908894878590893
202114Sonali Patole959092889290914
202115Axar Patel858082869284851
202116Meena Mishra787580748577783
202117Mahesh Kumbhar758075788076775
202118Sakshi Patil807874788077782
202119Sopan Bhore706875758080752
202220Prajwal Lokhande808585757880814
202221Anuja Wanare858886828485855
202222Venkatesh Iyer908987909291903
202223Anushka Sen707571748078751
202224Aakash Jain807572748580784
202225Akshay Agarwal858078889082845

Example 1: Write a query to remove records from Diploma_Student where the Student_Id are 202224 and 202225.

DELETE FROM Diploma_Student WHERE Student_Id IN (202224, 202225);

The above query deletes student details from the Diploma_Student where the Student_Id is 202224 and 202225. We will run the select query to check whether the student’s detail is removed or not from the table.

SELECT * FROM Diploma_Student;   

The output of the above query is as follows:

Student_IdStudent_NameFirst_SemSecond_SemThird_SemFourth_SemFifth_SemSixth_SemTotalDepartment_Id
202111Vaishnavi Patil949188859592911
202112Vaibhav Lokhande859092808582862
202113Yash Dhull908894878590893
202114Sonali Patole959092889290914
202115Axar Patel858082869284851
202116Meena Mishra787580748577783
202117Mahesh Kumbhar758075788076775
202118Sakshi Patil807874788077782
202119Sopan Bhore706875758080752
202220Prajwal Lokhande808585757880814
202221Anuja Wanare858886828485855
202222Venkatesh Iyer908987909291903
202223Anushka Sen707571748078751
DELETE VS DROP In SQL

Example 2: Write a query to remove all the data from the table.

DELETE FROM Diploma_Student;

The above query deletes all the data from the Diploma_Student table.

The output of the above query will be the empty set. As we deleted all the records, the table is empty.

DELETE VS DROP In SQL

What is DROP Command in SQL?

The DROP is a Data Definition Language used to remove the elements schemas, like table schema, constraints, etc. The DROP command is also used to remove the index, view, and database.

The syntax of the DROP command is:

DROP TABLE Table_Name;

The above syntax is used to remove the table from the database.

Example of DROP command

Consider the already existing table named Employees:

EMPLOYEE_IDFIRST_NAMELAST_NAMESALARYCITYDEPARTMENTMANAGERID
1001VAIBHAVIMISHRA65500PUNEORACLE1
1002VAIBHAVSHARMA60000BANGALOREC#4
1003NIKHILVANI50500HYDERABADFMW2
2001PRACHISHARMA55500CHANDIGARHORACLE1
2002BHAVESHJAIN65500PUNEFMW2
2003RUCHIKAJAIN50000MUMBAIC#4
3001PRANOTISHENDE55500PUNEJAVA3
3002ANUJAWANRE50500HYDERABADFMW2
3003DEEPAMJAUHARI58500MUMBAIJAVA3
4001RAJESHGOUD60500MUMBAITESTING5
4002ASHWINIBAGHAT54500BANGALOREJAVA3
4003RUCHIKAAGARWAL60000DELHIORACLE1
5001ARCHITSHARMA55500DELHITESTING5
5002RAKESHKUMAR70000CHANDIGARHC#4
5003MANISHSHARMA62500BANGALORETESTING5

Example: Write a query to drop employees' tables from the database.

DROP TABLE Employees;

The above query drops the employees' table from the database as we run the select query; the table doesn't exist displayed as output.

The output of the above query is as follows:

DELETE VS DROP In SQL

Now, let's discuss more differences between the DELETE and DROP queries in the query:

Sr.NoDELETEDROP
1DELETE command is used to delete all the records or the specific records from the tableDROP command is used to drop all the schema, constraints, and tables from the database.
2DELETE is a DML commandDROP is a DDL command
3We can use the WHERE clause in the DELETE query.No use of the WHERE clause in the DROP query.
4We can roll back the operation performed on the DELETE queryWe cannot roll back the operation performed on the DROP query.
5Doesn’t free the memory spaceFrees the memory space
6Shortage of MemoryMemory Fragmentation

Related Topics

SQL Queries

In a database, queries are used to request the result set of data from the table or action on the records. A Query can answer your simple or complicated question, perform...

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 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.

How to use COUNT in SQL?

How to use COUNT in SQL Introduction COUNT( ) is an aggregate function in SQL.This function counts the number of records in a table if the condition is not specified.If the condition...

4 minutes read.

How to use LIKE in SQL

In this SQL article, we will learn and understand how to use LIKE to the columns in the SQL tables. What is Like? Like is an operator in the SQL. It is...

7 minutes read.

SQL Left Join

The SQL Left Join query displays all the records from the table and displays similar records from the right table. The query displays zero records if it doesn’t find any...

4 minutes read.

SQL NOT Operator

SQL NOT is a Boolean operator used with the WHERE clause. NOT operator shows the records if the expression is false. When we use the NOT operator, we fetch only...

7 minutes read.

SQL SELECT AVG

In this tutorial, we will learn about the aggregate function name avg() function concept in SQL with the help of examples. The AVG() function is one of the aggregate functions in...

3 minutes read.

SQL Alter Table

In Structured Query Language, if you want to add columns in an existing table, then modify the table, or delete columns from the table. All these operations are allowed only...

7 minutes read.

SQL Truncate

This command deletes all records from table. Truncate is a DDL command. Syntax: TRUNCATE table table_name; Example: Truncate table teacher; ORDER BY The ORDER BY clause arranges the table or column in ascending...

5 minutes read.

SQL SubQuery

The Sub-query in the SQL is the inner query placed or positioned inside another query, which is also known is the outer query. The inner query is embedded in the...

6 minutes read.

SQL SELECT IN

SQL SELECT IN is a logical operator in Structured Query Language. It is used in SQL queries to reduce the use of multiple 'OR' operators. s The IN operator in SQL...

6 minutes read.

SQL Auto Increment

As we all know, In SQL for unique identification, we assign a column with the primary key. But in some tables, we find difficult to differentiate a column as a...

5 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 OR Operator

This SQL tutorial explains and helps us understand how to use the OR operator in the SELECT query with examples. The OR operator in the Structured Query Language is used to...

3 minutes read.

SQL Commands

SQL commands are classified into four groups on the basis of their nature. DDL (Data Definition Language) DML (Data Manipulation Language) DCL (Data Control Language) DQL (Data Query Language) NOTE: This...

1 minute read.

SQL Injection

SQL injection is a technique, this may destroy the database. It is one type of hacking technique. SQL IN WEB PAGES: Injection occurs when we ask for input like an id or...

3 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.

SQL SELECT MIN

The SQL Min() function is an aggregate function in SQL. SQL Min() returns the minimum value of a given condition. The expression may be numerical, or it may be an expression. The syntax...

5 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.