Skip to content
Related Articles

Related Articles

Improve Article

SQL | DELETE Statement

  • Difficulty Level : Easy
  • Last Updated : 28 Jun, 2021


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.

Basic Syntax:

Attention reader! Don’t stop learning now. Learn SQL for interviews using SQL Course  by GeeksforGeeks.

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.

Sample Table:
table1



Example Queries:

  • Deleting single record: Delete the rows where NAME = ‘Ram’. This will delete only the first row.
    DELETE FROM Student WHERE NAME = 'Ram';
    

    Output:
    The above query will delete only the first row and the table Student will now look like,

    ROLL_NONAMEADDRESSPHONEAge
    2RAMESHGURGAONXXXXXXXXXX18
    3SUJITROHTAKXXXXXXXXXX20
    4SURESHDelhiXXXXXXXXXX18
    3SUJITROHTAKXXXXXXXXXX20
    2RAMESHGURGAONXXXXXXXXXX18
  • 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;
    

    Output:
    The above query will delete two rows(third row and fifth row) and the table Student will now look like,

    ROLL_NONAMEADDRESSPHONEAge
    1RamDelhiXXXXXXXXXX18
    2RAMESHGURGAONXXXXXXXXXX18
    4SURESHDelhiXXXXXXXXXX18
    2RAMESHGURGAONXXXXXXXXXX18
  • Delete all of the records: There are two queries to do this as shown below,
    query1: "DELETE FROM Student";
    
    query2: "DELETE * FROM Student";
    

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

SQL Quiz

This article is contributed by Harsh Agarwal. If you like GeeksforGeeks and would like to contribute, you can also write an article using write.geeksforgeeks.org or mail your article to review-team@geeksforgeeks.org. 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.

My Personal Notes arrow_drop_up
Recommended Articles
Page :