×

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

Check Constraint in SQL

The Check Constraint in SQL is the rule or set of rules used to limit the data range that can be entered in a table column. Check constraint is used...

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

SQL SELECT LIKE Operator

The SQL SELECT LIKE Operator tutorial helps us understand how to use the LIKE operator in the SELECT query with examples. The SQL SELECT LIKE Operator retrieves the records from the...

4 minutes read.

How to Add Foreign Key in SQL?

How to Add Foreign Key in SQL Foreign key is an attribute or a set of attributes that references to primary key of same table or another table (relation). Foreign key creation along...

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

Grant Command in SQL

What is DCL (Data Control Language)? Data Control Language (DCL) is a computer programming language with syntax intended to manage access to data kept in databases. It is a part of...

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

DML Commands in SQL

DML is an abbreviation of Data Manipulation Language. Data Manipulation Language commands in Structured Query Language manipulate the data in the database. DML commands are used to retrieve records, add records,...

4 minutes read.

SQL CONSTRAINTS

SQL Constraints specifies the rules/limitations/restrictions for data present in table. SQL Constraints are specified at the time of table creation or after table creation using ALTER command. There are two...

5 minutes read.

SQL Aggregate Functions

In this tutorial, we will learn and understand the SQL Aggregate Functions concept with the help of examples. SQL Aggregate Function is a function used to perform calculation operations on one...

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.

What is SQL Injection?

Introduction to SQL Injection SQL injection is a vulnerability or a technique that might destroy the database of a website or a web application. It is one of the most widely...

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

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.

Nth highest salary

The most common and important question asked in interviews that how we can find the Nth highest salary in a table (2nd highest salary, 3rd highest salary, or Nth highest...

6 minutes read.

How to remove duplicates in SQL

Introduction There are some specific rules that needs to be followed while creating the database objects. To improve the performance of a database, a primary key, clustered and non-clustered indexes, and...

9 minutes read.

SQL SELECT SUM

The SQL Sum() function is an aggregate function in SQL that returns the total values of an expression. The expression may be numerical, or it may be an expression. Syntax: SELECT SUM(columnname)...

3 minutes read.

SQL CRUD Operation

In any computer language, CRUD operation is a foundation. CRUD operation rules are applied in databases as well. These operations are the basic operations used to perform with any database...

7 minutes read.