The Wayback Machine - https://web.archive.org/web/20240720075413/https://www.geeksforgeeks.org/sql-delete-statement/
Open In App

SQL DELETE Statement

Last Updated : 06 Jun, 2024
Improve
Suggest changes
Post a comment
Like Article
Like
Save
Share
Report

SQL DELETE is a basic SQL operation used to delete data in a database. SQL DELETE is an important part of database management DELETE can be used to selectively remove records from a database table based on certain conditions. This SQL DELETE operation is important for database size management, data accuracy, and integrity.

Syntax: 

DELETE FROM table_name

WHERE some_condition;

Parameter Explanation

  • Some_condition: condition to choose a particular record.
  • table_name: name of the table

Note: We can delete single as well as multiple records depending on the condition we provide in the WHERE clause. If we omit the WHERE clause then all of the records will be deleted and the table will be empty. 

The sample table is as follows GFG_Employees:

Query:

Assume we have created a table named GFG_Employee which contains the personal details of the Employee including their id, name, email and department etc. as shown below −

CREATE TABLE GFG_Employees (
   id INT PRIMARY KEY,
   name VARCHAR (20) ,
   email VARCHAR (25),
   department VARCHAR(20)
);
INSERT INTO GFG_Employees (id, name, email, department) VALUES 
(1, 'Jessie', 'jessie23@gmail.com', 'Development'),
(2, 'Praveen', 'praveen_dagger@yahoo.com', 'HR'),
(3, 'Bisa', 'dragonBall@gmail.com', 'Sales'),
(4, 'Rithvik', 'msvv@hotmail.com', 'IT'),
(5, 'Suraj', 'srjsunny@gmail.com', 'Quality Assurance'),
(6, 'Om', 'OmShukla@yahoo.com', 'IT'),
(7, 'Naruto', 'uzumaki@konoha.com', 'Development');
Select * From GFG_Employees

Output

GFG_Employee

GFG_Employees

Deleting Single Record

You can delete the records named Rithvik by using the below query:

Query

DELETE FROM GFG_Employees WHERE NAME = 'Rithvik';  

Output

DeleteSingleRecord

Deleting Multiple Records

Delete the rows from the table  GFG_Employees where the department is “Development”. This will delete 2 rows(the first row and the seventh row).

Query

DELETE FROM GFG_Employees 
WHERE department = 'Development';

Output

output

output

Delete All of the Records

To remove all the entries from the table, you can use the following query:

Query

DELETE FROM GFG_EMPLOyees;
Or
DELETE * FROM GFG_EMPLOyees; 

Output

All of the records in the table will be deleted, there are no records left to display. The table GFG_EMPLOyees  will become empty.

output

output

Important Note:

DELETE is a DML (Data Manipulation Language) command hence operation performed by DELETE can be 
rolled back or undone.

Conclusion

Existing records in a table can be deleted using the SQL DELETE Statement. We can delete a single record or multiple records depending on the condition we specify in the WHERE clause and With DELETE statament, you can filter the uncommitted records from the table.


Previous Article
Next Article

Similar Reads

How to Use PL SQL Insert, Update, Delete And Select Statement?
PL/SQL is a powerful extension of SQL specifically designed for Oracle databases. It enables developers to create procedural logic and execute SQL commands within Oracle database environments. In this article, we will explore the usage of fundamental PL/SQL statements such as INSERT, UPDATE, DELETE and SELECT with he help of various examples which
6 min read
DELETE Statement in MS SQL Server
The DELETE statement in MS SQL Server deletes specified records from the table. SyntaxMS SQL Server DELETE statement syntax is: DELETE FROM table_name WHERE condition; Note: Always use the DELETE statement with WHERE clause. The WHERE clause specifies which record(s) need to be deleted. If you exclude the WHERE clause, all records in the table will
1 min read
MySQL DELETE Statement
In DBMS, CRUD operations (Create, Read, Update, Delete) are essential for effective data management. The Delete operation is crucial for removing data from a database. This guide covers the MySQL DELETE statement, exploring its syntax and providing examples. Understanding how DELETE works helps ensure accurate and safe data removal, preventing acci
6 min read
Difference between Structured Query Language (SQL) and Transact-SQL (T-SQL)
Structured Query Language (SQL): Structured Query Language (SQL) has a specific design motive for defining, accessing and changement of data. It is considered as non-procedural, In that case the important elements and its results are first specified without taking care of the how they are computed. It is implemented over the database which is drive
2 min read
Configure SQL Jobs in SQL Server using T-SQL
In this article, we will learn how to configure SQL jobs in SQL Server using T-SQL. Also, we will discuss the parameters of SQL jobs in SQL Server using T-SQL in detail. Let's discuss it one by one. Introduction :SQL Server Agent is a component used for database task automation. For Example, If we need to perform index maintenance on Production ser
7 min read
Difference Between ON DELETE CASCADE and ON DELETE SET NULL in DBMS
The phrases "ON DELETE CASCADE" and "ON DELETE SET NULL" refer to options that can be specified when defining foreign key constraints in relational databases. These options determine the behavior of the database system when a record in the parent table (referenced table) is deleted. Let's explore each option: ON DELETE CASCADEWhen you specify an "O
3 min read
Reverse Statement Word by Word in SQL server
To reverse any statement Word by Word in SQL server we could use the SUBSTRING function which allows us to extract and display the part of a string. Pre-requisite :SUBSTRING function Approach : Declared three variables (@Input, @Output, @Length) using the DECLARE statement. Use the WHILE Loop to iterate every character present in the @Input. For th
2 min read
Select statement in MS SQL Server
In this article, the most basic statement used in SQL is being discussed. Basic statement: select There are large amounts of data available everywhere. The data is stored in a sequential order in form of a table. Each table consists of a row which represents a unique record and column represents a field. Schemas are used to arrange the tables in a
2 min read
Insert statement in MS SQL Server
A database contains of many tables which has data stored in an order. To add up the rows, the user needs to use insert statement. Syntax : insert into table_name(column_list) values(values_list) For better understanding, an example is given below. Example - A table named student must have values inserted into it. It has to be done as follows: inser
2 min read
Insert Into Select statement in MS SQL Server
Prerequisites - Insert statement in MS SQL Server, Select statement in MS SQL Server Consider a university database. There are two tables namely Student and Marks. In case, the marks of a few students has to be transferred from the marks table to the marks table, there are many ways to do so. One can use subqueries (query nested in another query) b
2 min read
Article Tags :
three90RightbarBannerImg