Open In App

SQL DELETE Statement

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Share
Report issue
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_Empoyees (
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,Developmet),
(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_Employee

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

output

output

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.


Last Updated : 30 Oct, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads