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:
| ID | STUDENT_NAME | CITY | GRADE |
|---|---|---|---|
| 201 | Aryan Verma | Lucknow | A |
| 202 | Riya Sharma | Bhopal | B+ |
| 203 | Karan Mehta | Jaipur | A- |
| 204 | Neha Gupta | Mumbai | B |
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
SELECTwith the same WHERE first to preview affected rows. - Wrap deletes in a transaction so you can
ROLLBACKif 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