Open In App

SQL DELETE Statement

Last Updated : 05 Aug, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

The SQL DELETE statement is an essential command in SQL used to remove one or more rows from a database table. Unlike the DROP statement, which removes the entire table, the DELETE statement removes data (rows) from the table retaining only the table structure, constraints and schema. Whether you need to delete a single row based on a condition or remove an entire dataset, understanding this command will help you manage your data effectively.

Syntax: 

DELETE FROM table_name

WHERE some_condition;

Parameter Explanation

  • Some_condition: A condition used to filter the rows you want to delete.
  • table_name: The name of the table from which you want to delete the rows

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.

Examples of SQL DELETE Statement

Assume we have created a table named GFG_Employee in SQL, 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', '[email protected]', 'Development'),
(2, 'Praveen', '[email protected]', 'HR'),
(3, 'Bisa', '[email protected]', 'Sales'),
(4, 'Rithvik', '[email protected]', 'IT'),
(5, 'Suraj', '[email protected]', 'Quality Assurance'),
(6, 'Om', '[email protected]', 'IT'),
(7, 'Naruto', '[email protected]', 'Development');

Select * From GFG_Employees

Output

GFG_Employees

Example 1: Deleting Single Record

We can use the DELETE statement with a condition to delete a specific row from a table. The WHERE clause ensures only the intended record is removed. We can delete the records named Rithvik by using the below query:

Query:

DELETE FROM GFG_Employees WHERE NAME = 'Rithvik';  

Output:

DeleteSingleRecord

Example 2: Deleting Multiple Records

To delete multiple records, you can specify a condition that matches several rows. Let's 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

Example 3: Delete All Records from a Table

If we need to delete all records from the table, we can omit the WHERE clause, or alternatively use the DELETE statement with an asterisk (*) to denote all rows.

Query:

DELETE FROM GFG_Employees;
Or
DELETE * FROM GFG_Employees;

Output:

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

Rolling Back DELETE Operations

Since the DELETE statement is a DML operation, it can be rolled back when executed in a statement. If you accidentally delete records or need to repeat the process, you can use the ROLLBACK command.

Query:

START TRANSACTION;
DELETE FROM GFG_Employees WHERE department = 'Development';
-- If needed, you can rollback the deletion
ROLLBACK;

Explanation: The ROLLBACK command will undo the changes made by the DELETE statement, effectively restoring the records that were deleted during the transaction.


Article Tags :
Practice Tags :

Similar Reads