SQL Tutorial

SQL DELETE Statement

SQL DELETE Statement
SQL DELETE Statement

SQL DELETE Statement

The SQL DELETE statement is used to remove rows from a table. Based on a condition, it permits deletion of one or more records. If the WHERE clause is not included, all records in the table will be removed.

Complete Python Course with Advance topics:-
SQL Tutorial:-

SQL DELETE Syntax

DELETE FROM table_name [WHERE condition];
  • table_name: The table from which records are deleted.
  • WHERE condition: Specifies which rows to delete. If omitted, all rows are deleted.

SQL DELETE Example

Consider a table named STUDENT:

IDSTUDENT_NAMECITYGRADE
201Aryan VermaLucknowA
202Riya SharmaBhopalB+
203Karan MehtaJaipurA-
204Neha GuptaMumbaiB

Deleting a Specific Record

DELETE FROM STUDENT WHERE ID = 201;

Deleting All Records

DELETE FROM STUDENT;

This removes every row from the STUDENT table while keeping the table structure intact.

DELETE with a Subquery

You can delete rows based on data from another table using a subquery.

DELETE FROM STUDENT
WHERE CITY IN (SELECT city FROM closed_centers);

DELETE vs TRUNCATE vs DROP

  • DELETE: Removes selected rows, can use WHERE, can be rolled back, fires triggers.
  • TRUNCATE: Removes ALL rows quickly, no WHERE, resets auto-increment, minimal logging.
  • DROP: Removes the entire table including its structure.

Importance of the WHERE Clause

The WHERE clause is crucial in a DELETE statement as it prevents unintended deletion of all records. Omitting WHERE may result in losing all data in the table.

Invalid DELETE Statement in Oracle

In Oracle, using * in the DELETE statement is invalid:

DELETE * FROM STUDENT;   -- Error
DELETE FROM STUDENT;     -- Correct

Best Practices

  • Always run a SELECT with the same WHERE first to preview affected rows.
  • Wrap deletes in a transaction so you can ROLLBACK if needed.
  • Back up the table before bulk deletes.

Download New Real Time Projects:- Click here
Complete Advance AI topics:-

Conclusion

The DELETE statement is fundamental for maintaining clean databases. By always using the WHERE clause, previewing rows, and wrapping operations in transactions, you keep your data accurate and safe. For more SQL tutorials, visit .

delete all data from table sql
sql delete statement w3schools
delete row in sql
sql delete statement example
delete vs truncate sql
delete with subquery sql
delete table query in sql
delete query in mysql

Source Code Available

Interested in This Project?

Get the complete source code for this project at a very affordable price — perfect for your portfolio, college submission, or learning. Message us on WhatsApp and we'll get back to you instantly!

Full source code included Step-by-step setup guide Instant delivery on WhatsApp Instant reply on WhatsApp
Chat on WhatsApp

We usually reply within a few minutes

Leave a Reply

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

Chat with us