Download the BYJU'S Exam Prep App for free GATE/ESE preparation videos & tests - Download the BYJU'S Exam Prep App for free GATE/ESE preparation videos & tests -

DELETE Statement in SQL

The DELETE command refers to a data manipulation language (DML) command that is used to remove the records present in a table. Here, either all records can be removed in a single go, or just a set of records could be deleted on the basis of a condition.

In this article, we will dive deeper into the DELETE Statement in SQL according to the GATE Syllabus for (Computer Science Engineering) CSE. Keep reading ahead to learn more.

Table of Contents

What is a DELETE Statement in SQL?

In SQL, the DELETE statement is used to delete records from a table. Depending on the condition we set in the WHERE clause, we can delete a single record or numerous records.

Syntax:

DELETE FROM name_of_table WHERE some_condition;

name_of_table: the name of the table

some_condition: the condition required to choose a particular record

Note: Depending on the condition we provide in the WHERE clause, we can remove single or numerous records. If we don’t utilise the WHERE clause, the table will be empty, and all of the records will be erased.

Sample Table

ID_NO NAME ADDRESS MOBILE Age
D1 RAM Delhi xxxxxxxxxx 28
D2 RAMESH GURGAON xxxxxxxxxx 28
D3 SUJIT ROHTAK xxxxxxxxxx 30
D4 SURESH Delhi xxxxxxxxxx 28
D3 SUJIT ROHTAK xxxxxxxxxx 30
D2 RAMESH GURGAON xxxxxxxxxx 28

Example Queries

Deleting a Single Record

Let us delete the rows wherever NAME = ‘Ram’. Thus, it would only delete the very first row.

DELETE FROM Employee WHERE NAME = ‘Ram’;

Output:

The query stated above would only delete the first row. Thus, the table Employee would now look like this:

ID_NO NAME ADDRESS MOBILE Age
D2 RAMESH GURGAON xxxxxxxxxx 28
D3 SUJIT ROHTAK xxxxxxxxxx 30
D4 SURESH Delhi xxxxxxxxxx 28
D3 SUJIT ROHTAK xxxxxxxxxx 30
D2 RAMESH GURGAON xxxxxxxxxx 28

Deleting Multiple Records

We will now delete the rows from the Employee table wherever Age is 30. Thus, it would delete two rows (the third and the fifth row).

DELETE FROM Employee WHERE Age = 30;

Output:

Thus, the query stated above would delete two of the rows in it (the third and the fifth row). Thus, the Employee table would look like this now:

ID_NO NAME ADDRESS MOBILE Age
D1 RAM Delhi xxxxxxxxxx 28
D2 RAMESH GURGAON xxxxxxxxxx 28
D4 SURESH Delhi xxxxxxxxxx 28
D2 RAMESH GURGAON xxxxxxxxxx 28

Deleting All of the Records

To do this, there are two queries as depicted below:

query1: “DELETE FROM Employee”;

query2: “DELETE * FROM Employee”;

Output:

All the records present in the table would be deleted, and then there would be no records left to display. Thus, the Employee table would become empty in this case.

Keep learning and stay tuned to get the latest updates on the GATE Exam along with Eligibility Criteria, GATE Syllabus for CSE (Computer Science Engineering), GATE CSE Notes, GATE CSE Question Paper, and more.

Also Explore,

Comments

Leave a Comment

Your Mobile number and Email id will not be published.

*

*