A database contains many tables that have data stored in order. To delete the rows, the user needs to use a delete statement.
1. To DELETE a single record :
Syntax –
DELETE FROM table_name WHERE condition;
Note –
Take care when deleting records from a table. Note that the WHERE clause in the DELETE statement. This WHERE specifies which record(s) need to be deleted. If you exclude the WHERE clause, all records in the table would be deleted.
Example –
A table named Student has multiple values inserted into it and we need to delete some value.
| StudentName | RollNo | City |
|---|---|---|
| ABC | 1 | Jaipur |
| DEF | 2 | Delhi |
| JKL | 3 | Noida |
| XYZ | 4 | Delhi |
The following SQL statement deletes a row from “Student” table which has StudentName as ‘ABC’.
DELETE FROM student WHERE StudentName = 'ABC';
Output –
(1 row(s) affected)
To check whether the value is actually deleted, the query is as follows :
select * from student;
Output –
| StudentName | RollNo | City |
|---|---|---|
| DEF | 2 | Delhi |
| JKL | 3 | Noida |
| XYZ | 4 | Delhi |
2. To DELETE all the records :
It is possible to delete all rows from a table without deleting the table. This means that the table structure, attributes, and indexes are going to be intact.
Syntax –
DELETE FROM table_name;
Example –
The following SQL statement deletes all rows from “Student” table, without deleting the table.
DELETE FROM student;
Output –
(3 row(s) affected)
To check whether the value is actually deleted, the query is as follows :
select * from student;
| StudentName | RollNo | City |
|---|
Attention reader! Don’t stop learning now. Get hold of all the important CS Theory concepts for SDE interviews with the CS Theory Course at a student-friendly price and become industry ready.
Recommended Posts:
- Select statement in MS SQL Server
- Insert statement in MS SQL Server
- Insert Into Select statement in MS SQL Server
- SQL | DELETE Statement
- Delete Action in MS SQL Server
- Delete Database in MS SQL Server
- Delete Duplicates in MS SQL Server
- Difference between Structured Query Language (SQL) and Transact-SQL (T-SQL)
- SQL | INSERT INTO Statement
- SQL | UPDATE Statement
- SQL | INSERT IGNORE Statement
- SQL | Case Statement
- SQL | DESCRIBE Statement
- SQL | MERGE Statement
- MERGE Statement in SQL Explained
- SELECT INTO statement in SQL
- CREATE and DROP INDEX Statement in SQL
- SQL Server Mathematical functions (SQRT, PI, SQUARE, ROUND, CEILING & FLOOR)
- SQL Server Identity
- SQL SERVER | Conditional Statements
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

