BeginnersBook

  • Home
  • Java
    • Java OOPs
    • Java Collections
    • Java Examples
  • C
    • C Examples
  • C++
    • C++ Examples
  • DBMS
  • Computer Network
  • Python
    • Python Examples
  • More…
    • jQuery
    • Kotlin
    • WordPress
    • SEO
    • JSON
    • JSP
    • JSTL
    • Servlet
    • MongoDB
    • XML
    • Perl

DELETE Query in SQL

Last Updated: September 10, 2022 by Chaitanya Singh | Filed Under: SQL

Delete Query is used for deleting the existing rows(records) from table. Generally DELETE query is used along with WHERE clause to delete the certain number of rows that fulfills the specified condition. However DELETE query can be used without WHERE clause too, in that case the query would delete all the rows of specified table.

Syntax

1) To Delete a particular set of rows:

DELETE FROM TableName
WHERE condition;

2) To Delete all the rows of a table:

DELETE FROM TableName;

Example:

Lets take the same table EMPLOYEES which we had in the last tutorial.

+------+----------+---------+----------+
|SSN   | EMP_NAME | EMP_AGE |EMP_SALARY|
+------+----------+---------+----------+
|  101 | Steve    |  23     |  9000.00 |
|  223 | Peter    |  24     |  2550.00 |
|  388 | Shubham  |  19     |  2444.00 |
|  499 | Chaitanya|  29     |  6588.00 |
|  589 | Apoorv   |  21     |  1400.00 |
|  689 | Rajat    |  24     |  8900.00 |
|  700 | Ajeet    |  20     | 18300.00 |
+------+----------+---------+----------+

Delete all the records that have SSN greater than 400:

SQL> DELETE FROM EMPLOYEES
WHERE SSN > 400;

After the successful execution of above query the table would be having below mentioned records:

+------+----------+---------+----------+
|SSN   | EMP_NAME | EMP_AGE |EMP_SALARY|
+------+----------+---------+----------+
|  101 | Steve    |  23     |  9000.00 |
|  223 | Peter    |  24     |  2550.00 |
|  388 | Shubham  |  19     |  2444.00 |
+------+----------+---------+----------+

Delete the data of employees having age greater than or equal to 24:

SQL> DELETE FROM EMPLOYEES
WHERE EMP_AGE >=24;

Result:

+------+----------+---------+----------+
|SSN   | EMP_NAME | EMP_AGE |EMP_SALARY|
+------+----------+---------+----------+
|  101 | Steve    |  23     |  9000.00 |
|  388 | Shubham  |  19     |  2444.00 |
+------+----------+---------+----------+

DELETE all the records of table EMPLOYEES

SQL> DELETE FROM EMPLOYEES;

Top Related Articles:

  1. SQL – DROP Table Statement to delete the entire table
  2. SQL WHERE Clause
  3. Introduction to SQL
  4. SQL UPDATE Statement
  5. SQL SELECT AVG() Function

About the Author

I have 15 years of experience in the IT industry, working with renowned multinational corporations. Additionally, I have dedicated over a decade to teaching, allowing me to refine my skills in delivering information in a simple and easily understandable manner.

– Chaitanya

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

SQL Tutorial

  • SQL Tutorial
  • SQL Introduction
  • SQL Syntax
  • SQL Data Types

SQL Database

  • SQL CREATE DB
  • SQL DROP DB
  • SQL Rename DB
  • SQL USE DB

SQL Queries

  • SQL Select
  • SQL Select Distinct
  • SQL Select Count
  • SQL Select Top
  • SQL Where
  • SQL AND, OR & NOT
  • SQL Order By
  • SQL Insert Into
  • SQL Insert Into SELECT
  • SQL Select Random
  • SQL Alias
  • SQL NULL Check
  • SQL Update
  • SQL Delete
  • SQL MIN, MAX
  • SQL SUM
  • SQL AVG

Copyright © 2012 – 2025 BeginnersBook . Privacy Policy . Sitemap