The DELETE Statement in SQL is used to delete existing records from a table. We can delete a single record or multiple records depending on the condition we specify in the WHERE clause.
DELETE FROM table_name WHERE some_condition; table_name: name of the table some_condition: condition to choose particular record.
Note: We can delete single as well as multiple records depending on the condition we provide in WHERE clause. If we omit the WHERE clause then all of the records will be deleted and the table will be empty.
- Deleting single record: Delete the rows where NAME = ‘Ram’. This will delete only the first row.
DELETE FROM Student WHERE NAME = 'Ram';
The above query will delete only the first row and the table Student will now look like,
ROLL_NO NAME ADDRESS PHONE Age 2 RAMESH GURGAON XXXXXXXXXX 18 3 SUJIT ROHTAK XXXXXXXXXX 20 4 SURESH Delhi XXXXXXXXXX 18 3 SUJIT ROHTAK XXXXXXXXXX 20 2 RAMESH GURGAON XXXXXXXXXX 18
- Deleting multiple records: Delete the rows from the table Student where Age is 20. This will delete 2 rows(third row and fifth row).
DELETE FROM Student WHERE Age = 20;
The above query will delete two rows(third row and fifth row) and the table Student will now look like,
ROLL_NO NAME ADDRESS PHONE Age 1 Ram Delhi XXXXXXXXXX 18 2 RAMESH GURGAON XXXXXXXXXX 18 4 SURESH Delhi XXXXXXXXXX 18 2 RAMESH GURGAON XXXXXXXXXX 18
- Delete all of the records: There are two queries to do this as shown below,
query1: "DELETE FROM Student"; query2: "DELETE * FROM Student";
All of the records in the table will be deleted, there are no records left to display. The table Student will become empty!
This article is contributed by Harsh Agarwal. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
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.
- Delete statement 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
- Select statement in MS SQL Server
- Insert statement in MS SQL Server
- Insert Into Select statement in MS SQL Server
- CREATE and DROP INDEX Statement in SQL
- Performing Database Operations in Java | SQL CREATE, INSERT, UPDATE, DELETE and SELECT
- Difference between DELETE and DROP in SQL
- Delete Action in MS SQL Server
- Delete Database in MS SQL Server
- Delete Duplicates in MS SQL Server
- SQL | Procedures in PL/SQL